[Python-checkins] bpo-36405: Use dict unpacking in idlelib (GH-12507)

Miss Islington (bot) webhook-mailer at python.org
Sat Mar 23 04:08:58 EDT 2019


https://github.com/python/cpython/commit/00986ec5530f004fca2c2675a822c73f06283bdf
commit: 00986ec5530f004fca2c2675a822c73f06283bdf
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-03-23T01:08:37-07:00
summary:

bpo-36405: Use dict unpacking in idlelib (GH-12507)


Remove now unneeded imports.
(cherry picked from commit 2b75155590eb42d25e474b776ee9fdcc4b3dc840)

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

files:
A Misc/NEWS.d/next/IDLE/2019-03-23-01-45-56.bpo-36405.m7Wv1F.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/autocomplete.py
M Lib/idlelib/calltip.py

diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 0cbd3ff935f8..9ae2b0a97239 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,8 @@ Released on 2019-??-??
 ======================================
 
 
+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.
 
diff --git a/Lib/idlelib/autocomplete.py b/Lib/idlelib/autocomplete.py
index 9caf50d5d0c2..6751928f0450 100644
--- a/Lib/idlelib/autocomplete.py
+++ b/Lib/idlelib/autocomplete.py
@@ -14,7 +14,6 @@
 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 @@ def fetch_completions(self, what, mode):
         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 @@ def fetch_completions(self, what, mode):
             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()
diff --git a/Lib/idlelib/calltip.py b/Lib/idlelib/calltip.py
index 2a9a131ed96b..4b78917d7d98 100644
--- a/Lib/idlelib/calltip.py
+++ b/Lib/idlelib/calltip.py
@@ -12,7 +12,6 @@
 
 from idlelib import calltip_w
 from idlelib.hyperparser import HyperParser
-import __main__
 
 
 class Calltip:
@@ -100,13 +99,12 @@ def fetch_tip(self, expression):
 
 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
index 000000000000..619ab6af80c9
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2019-03-23-01-45-56.bpo-36405.m7Wv1F.rst
@@ -0,0 +1 @@
+Use dict unpacking in idlelib and remove unneeded __main__ imports.



More information about the Python-checkins mailing list