Skip to content

Commit 2b75155

Browse files
authored
bpo-36405: Use dict unpacking in idlelib (#12507)
Remove now unneeded imports.
1 parent 7a2e84c commit 2b75155

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Released on 2019-10-20?
33
======================================
44

55

6+
bpo-36405: Use dict unpacking in idlelib and remove unneeded __main__ imports.
7+
68
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
79
This param was only used twice and changed the return type.
810

Lib/idlelib/autocomplete.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from idlelib import autocomplete_w
1515
from idlelib.config import idleConf
1616
from idlelib.hyperparser import HyperParser
17-
import __main__
1817

1918
# This string includes all chars that may be in an identifier.
2019
# TODO Update this here and elsewhere.
@@ -182,8 +181,7 @@ def fetch_completions(self, what, mode):
182181
else:
183182
if mode == COMPLETE_ATTRIBUTES:
184183
if what == "":
185-
namespace = __main__.__dict__.copy()
186-
namespace.update(__main__.__builtins__.__dict__)
184+
namespace = {**__builtins__.__dict__, **globals()}
187185
bigl = eval("dir()", namespace)
188186
bigl.sort()
189187
if "__all__" in bigl:
@@ -218,10 +216,8 @@ def fetch_completions(self, what, mode):
218216
return smalll, bigl
219217

220218
def get_entity(self, name):
221-
"""Lookup name in a namespace spanning sys.modules and __main.dict__"""
222-
namespace = sys.modules.copy()
223-
namespace.update(__main__.__dict__)
224-
return eval(name, namespace)
219+
"Lookup name in a namespace spanning sys.modules and globals()."
220+
return eval(name, {**sys.modules, **globals()})
225221

226222

227223
AutoComplete.reload()

Lib/idlelib/calltip.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from idlelib import calltip_w
1414
from idlelib.hyperparser import HyperParser
15-
import __main__
1615

1716

1817
class Calltip:
@@ -100,13 +99,12 @@ def fetch_tip(self, expression):
10099

101100
def get_entity(expression):
102101
"""Return the object corresponding to expression evaluated
103-
in a namespace spanning sys.modules and __main.dict__.
102+
in a namespace spanning sys.modules and globals().
104103
"""
105104
if expression:
106-
namespace = sys.modules.copy()
107-
namespace.update(__main__.__dict__)
105+
namespace = {**sys.modules, **globals()}
108106
try:
109-
return eval(expression, namespace)
107+
return eval(expression, namespace) # Only protect user code.
110108
except BaseException:
111109
# An uncaught exception closes idle, and eval can raise any
112110
# exception, especially if user classes are involved.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use dict unpacking in idlelib and remove unneeded __main__ imports.

0 commit comments

Comments
 (0)