-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-30441: Fix bug when modifying os.environ while iterating over it #2409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
375f977
cac586f
6bbfe8c
2190931
3b15ce0
a061788
4c3f4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -835,6 +835,31 @@ def test_key_type(self): | |
| self.assertIs(cm.exception.args[0], missing) | ||
| self.assertTrue(cm.exception.__suppress_context__) | ||
|
|
||
| def _test_environ_iteration(self, iterator): | ||
| new_key = "__new_key__" | ||
|
|
||
| next(iterator) # start iteration over os.environ.items | ||
|
|
||
| # add a new key in os.environ mapping | ||
| os.environ[new_key] = "test_environ_iteration" | ||
|
|
||
| next(iterator) # force iteration over modified mapping | ||
| self.assertEqual(os.environ[new_key], "test_environ_iteration") | ||
|
|
||
| del os.environ[new_key] | ||
|
|
||
| def test_iter_error_when_changing_os_environ(self): | ||
| iter_environ = iter(os.environ) | ||
| self._test_environ_iteration(iter_environ) | ||
|
|
||
| def test_iter_error_when_changing_os_environ_items(self): | ||
| iter_environ_items = iter(os.environ.items()) | ||
| self._test_environ_iteration(iter_environ_items) | ||
|
|
||
| def test_iter_error_when_changing_os_environ_values(self): | ||
| iter_environ_values = iter(os.environ.values()) | ||
| self._test_environ_iteration(iter_environ_values) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why repeat "iter environ values" so much times? Why not inline the |
||
|
|
||
|
|
||
| class WalkTests(unittest.TestCase): | ||
| """Tests for os.walk().""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1760,3 +1760,4 @@ Jelle Zijlstra | |
| Gennadiy Zlobin | ||
| Doug Zongker | ||
| Peter Åstrand | ||
| Osvaldo Santana Neto | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Names are ordered in alphabetical order. You name presumably should be under the letter N.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? I didn't see an alphabetical order, so, I assumed I should put my name at the end of file...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! I see now!... It's alphabetical order of surname (not the first name) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix bug when modifying os.environ while iterating over it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new key should be removed even if the test is failed, otherwise it could affect other tests. Use try...finally.