]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36405: Use dict unpacking in idlelib (#12507)
authorTerry Jan Reedy <tjreedy@udel.edu>
Sat, 23 Mar 2019 07:50:15 +0000 (03:50 -0400)
committerGitHub <noreply@github.com>
Sat, 23 Mar 2019 07:50:15 +0000 (03:50 -0400)
Remove now unneeded imports.

Lib/idlelib/NEWS.txt
Lib/idlelib/autocomplete.py
Lib/idlelib/calltip.py
Misc/NEWS.d/next/IDLE/2019-03-23-01-45-56.bpo-36405.m7Wv1F.rst [new file with mode: 0644]

index d79d9ce648f5ee3ab43598edfd0d8aa0179eedcd..d31ca83b0aac5452c72f0f3e8442cb55b301bdab 100644 (file)
@@ -3,6 +3,8 @@ Released on 2019-10-20?
 ======================================
 
 
+bpo-36405: Use dict unpacking in idlelib and remove unneeded __main__ imports.
+
 bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
 This param was only used twice and changed the return type.
 
index 9caf50d5d0c21c8820be91fea89e5735457e6239..6751928f045024ca8966ffd7b3bfffbfd3490b1c 100644 (file)
@@ -14,7 +14,6 @@ COMPLETE_ATTRIBUTES, COMPLETE_FILES = range(1, 2+1)
 from idlelib import autocomplete_w
 from idlelib.config import idleConf
 from idlelib.hyperparser import HyperParser
-import __main__
 
 # This string includes all chars that may be in an identifier.
 # TODO Update this here and elsewhere.
@@ -182,8 +181,7 @@ class AutoComplete:
         else:
             if mode == COMPLETE_ATTRIBUTES:
                 if what == "":
-                    namespace = __main__.__dict__.copy()
-                    namespace.update(__main__.__builtins__.__dict__)
+                    namespace = {**__builtins__.__dict__, **globals()}
                     bigl = eval("dir()", namespace)
                     bigl.sort()
                     if "__all__" in bigl:
@@ -218,10 +216,8 @@ class AutoComplete:
             return smalll, bigl
 
     def get_entity(self, name):
-        """Lookup name in a namespace spanning sys.modules and __main.dict__"""
-        namespace = sys.modules.copy()
-        namespace.update(__main__.__dict__)
-        return eval(name, namespace)
+        "Lookup name in a namespace spanning sys.modules and globals()."
+        return eval(name, {**sys.modules, **globals()})
 
 
 AutoComplete.reload()
index 2a9a131ed96b3c74d8f852d0678cc1c1782d4cfb..4b78917d7d98c11746e1abbe66183834f0ef0cf4 100644 (file)
@@ -12,7 +12,6 @@ import types
 
 from idlelib import calltip_w
 from idlelib.hyperparser import HyperParser
-import __main__
 
 
 class Calltip:
@@ -100,13 +99,12 @@ class Calltip:
 
 def get_entity(expression):
     """Return the object corresponding to expression evaluated
-    in a namespace spanning sys.modules and __main.dict__.
+    in a namespace spanning sys.modules and globals().
     """
     if expression:
-        namespace = sys.modules.copy()
-        namespace.update(__main__.__dict__)
+        namespace = {**sys.modules, **globals()}
         try:
-            return eval(expression, namespace)
+            return eval(expression, namespace)  # Only protect user code.
         except BaseException:
             # An uncaught exception closes idle, and eval can raise any
             # exception, especially if user classes are involved.
diff --git a/Misc/NEWS.d/next/IDLE/2019-03-23-01-45-56.bpo-36405.m7Wv1F.rst b/Misc/NEWS.d/next/IDLE/2019-03-23-01-45-56.bpo-36405.m7Wv1F.rst
new file mode 100644 (file)
index 0000000..619ab6a
--- /dev/null
@@ -0,0 +1 @@
+Use dict unpacking in idlelib and remove unneeded __main__ imports.