[Python-checkins] bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (#9701)

Yury Selivanov webhook-mailer at python.org
Thu Oct 4 15:26:37 EDT 2018


https://github.com/python/cpython/commit/476c294f260ebe1b44157a168c3dfa4a43724ce3
commit: 476c294f260ebe1b44157a168c3dfa4a43724ce3
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yury Selivanov <yury at magic.io>
date: 2018-10-04T15:26:33-04:00
summary:

bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (#9701)

https://bugs.python.org/issue34871
(cherry picked from commit 6f85b826b527e240551613aeec3118a5469e3a33)

Co-authored-by: INADA Naoki <methane at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2018-10-04-18-46-54.bpo-34871.t3X-dB.rst
M Lib/inspect.py

diff --git a/Lib/inspect.py b/Lib/inspect.py
index 4482b8ea29d5..b5d583ccfd1b 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1988,7 +1988,7 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
         module = sys.modules.get(module_name, None)
         if module:
             module_dict = module.__dict__
-    sys_module_dict = sys.modules
+    sys_module_dict = sys.modules.copy()
 
     def parse_name(node):
         assert isinstance(node, ast.arg)
diff --git a/Misc/NEWS.d/next/Library/2018-10-04-18-46-54.bpo-34871.t3X-dB.rst b/Misc/NEWS.d/next/Library/2018-10-04-18-46-54.bpo-34871.t3X-dB.rst
new file mode 100644
index 000000000000..8cff15671ce5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-04-18-46-54.bpo-34871.t3X-dB.rst
@@ -0,0 +1,2 @@
+Fix inspect module polluted ``sys.modules`` when parsing
+``__text_signature__`` of callable.



More information about the Python-checkins mailing list