summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-11-29 15:58:53 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-11-29 15:58:53 (GMT)
commita74f8ef419d2c7c5f398a80165f8d8fd5e4d7b8e (patch)
tree70524b8d668bbe4695982cef03dcba9d1aa28a1f
parentc4d7d8c49d3a78fc7eeb19588a9f44a74bec71e1 (diff)
downloadcpython-a74f8ef419d2c7c5f398a80165f8d8fd5e4d7b8e.zip
cpython-a74f8ef419d2c7c5f398a80165f8d8fd5e4d7b8e.tar.gz
cpython-a74f8ef419d2c7c5f398a80165f8d8fd5e4d7b8e.tar.bz2
Fix inspect.getmodule to use a copy of sys.modules for iteration (#13487).
This fixes a regression compared to 2.x, where sys.modules.items() returns a copy, as indicated by a comment in the source. Diagnosis and patch by Erik Tollerud.
-rw-r--r--Lib/inspect.py2
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
3 files changed, 5 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index bb46ea6..4e17f1b 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -483,7 +483,7 @@ def getmodule(object, _filename=None):
return sys.modules.get(modulesbyfile[file])
# Update the filename to module name cache and check yet again
# Copy sys.modules in order to cope with changes while iterating
- for modname, module in sys.modules.items():
+ for modname, module in list(sys.modules.items()):
if ismodule(module) and hasattr(module, '__file__'):
f = module.__file__
if f == _filesbymodname.get(modname, None):
diff --git a/Misc/ACKS b/Misc/ACKS
index 5d75404..4effde3 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -905,6 +905,7 @@ Christian Tismer
Frank J. Tobin
R Lindsay Todd
Bennett Todd
+Erik Tollerud
Matias Torchinsky
Sandro Tosi
Richard Townsend
diff --git a/Misc/NEWS b/Misc/NEWS
index f79e57a..2172853 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -87,6 +87,9 @@ Core and Builtins
Library
-------
+- Issue #13487: Make inspect.getmodule robust against changes done to
+ sys.modules while it is iterating over it.
+
- Issue #12618: Fix a bug that prevented py_compile from creating byte
compiled files in the current directory. Initial patch by Sjoerd de Vries.