Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8a8d2850
Commit
8a8d2850
authored
Jul 01, 2017
by
Osvaldo Santana Neto
Committed by
Serhiy Storchaka
Jul 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30441: Fix bug when modifying os.environ while iterating over it (#2409)
parent
85f64302
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
1 deletion
+29
-1
Lib/os.py
Lib/os.py
+3
-1
Lib/test/test_os.py
Lib/test/test_os.py
+24
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS.d/next/Library/2017-06-29-14-25-14.bpo-30441.3Wh9kc.rst
...S.d/next/Library/2017-06-29-14-25-14.bpo-30441.3Wh9kc.rst
+1
-0
No files found.
Lib/os.py
View file @
8a8d2850
...
...
@@ -697,7 +697,9 @@ class _Environ(MutableMapping):
raise
KeyError
(
key
)
from
None
def
__iter__
(
self
):
for
key
in
self
.
_data
:
# list() from dict object is an atomic operation
keys
=
list
(
self
.
_data
)
for
key
in
keys
:
yield
self
.
decodekey
(
key
)
def
__len__
(
self
):
...
...
Lib/test/test_os.py
View file @
8a8d2850
...
...
@@ -835,6 +835,30 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
self
.
assertIs
(
cm
.
exception
.
args
[
0
],
missing
)
self
.
assertTrue
(
cm
.
exception
.
__suppress_context__
)
def
_test_environ_iteration
(
self
,
collection
):
iterator
=
iter
(
collection
)
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"
try
:
next
(
iterator
)
# force iteration over modified mapping
self
.
assertEqual
(
os
.
environ
[
new_key
],
"test_environ_iteration"
)
finally
:
del
os
.
environ
[
new_key
]
def
test_iter_error_when_changing_os_environ
(
self
):
self
.
_test_environ_iteration
(
os
.
environ
)
def
test_iter_error_when_changing_os_environ_items
(
self
):
self
.
_test_environ_iteration
(
os
.
environ
.
items
())
def
test_iter_error_when_changing_os_environ_values
(
self
):
self
.
_test_environ_iteration
(
os
.
environ
.
values
())
class
WalkTests
(
unittest
.
TestCase
):
"""Tests for os.walk()."""
...
...
Misc/ACKS
View file @
8a8d2850
...
...
@@ -1088,6 +1088,7 @@ Fredrik Nehr
Tony Nelson
Trent Nelson
Andrew Nester
Osvaldo Santana Neto
Chad Netzer
Max Neunhöffer
Anthon van der Neut
...
...
Misc/NEWS.d/next/Library/2017-06-29-14-25-14.bpo-30441.3Wh9kc.rst
0 → 100644
View file @
8a8d2850
Fix bug when modifying os.environ while iterating over it
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment