[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: Checked in: r71875 (trunk) r71876 (release26-maint) r71881 (py3k) r71885 (release30-maint) -- resolution: -> fixed status: open -> closed ___ Python tracker __

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: You're right checking both in unset() and __exit__() fixes the importlib failures. I'll check in the fix. -- ___ Python tracker ___

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: This might have something to do with the _keymap hook. -- ___ Python tracker ___ ___ Python-bugs-lis

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Mark Dickinson
Mark Dickinson added the comment: It looks like the unset method should check whether the variable is set before trying to unset it. Perhaps this also needs to happen in the __exit__ method? -- ___ Python tracker

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: OK, I'll remove the clear method (which is a new feature) and then check it in. -- ___ Python tracker ___ __

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Mark Dickinson
Mark Dickinson added the comment: I take that back: this patch appears to break test_importlib on OS X 10.5.6 (py3k). Not sure why. -- ___ Python tracker ___ __

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Mark Dickinson
Mark Dickinson added the comment: Patch looks good to me, and (for py3k) all tests pass on my machine. As far as I can tell, there's currently no test for EvironmentVarGuard itself, though it's tested indirectly by other tests. It might be good to have some direct tests (including one for th

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: That's exactly what I was thinking too. Here's the patch. Running the test suite now. -- Added file: http://bugs.python.org/file13764/diff2.txt ___ Python tracker _

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Mark Dickinson
Mark Dickinson added the comment: Could you maybe get away with a single dict "changed", which would just record previous values (with None representing a value that was previously unset)? -- ___ Python tracker ___

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: If you want to restore only those environment variables that have change you somehow have to record which *do* have changed, i.e. you'd have to go through EnvironmentVarGuard again. I'm working on a patch that does that. --

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Mark Dickinson
Mark Dickinson added the comment: Is efficiency a concern here? I'm just imagining an environment with thousands of variables, but only a few changes being made---the old (broken) code just resets the variables that have changed, while the patched version resets all of the variables. --

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
Walter Dörwald added the comment: Here's a patch that changes EnvironmentVarGuard to make a copy of os.environ at the start. The set and unset methods are useless now, but I left them in for backwards compatibility. Should they be removed? -- Added file: http://bugs.python.org/file13763

[issue5837] support.EnvironmentVarGuard broken

2009-04-25 Thread Walter Dörwald
New submission from Walter Dörwald : support.EnvironmentVarGuard seems to be broken: import os from test import support print(os.environ.get("HOME")) with support.EnvironmentVarGuard() as env: env.unset("HOME") env.set("HOME", "foo") print(os.environ.get("HOME")) The output I get is: