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

Remove now unneeded imports.
This commit is contained in:
Terry Jan Reedy 2019-03-23 03:50:15 -04:00 committed by GitHub
parent 7a2e84c348
commit 2b75155590
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 12 deletions

View 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(). bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
This param was only used twice and changed the return type. This param was only used twice and changed the return type.

View file

@ -14,7 +14,6 @@ COMPLETE_ATTRIBUTES, COMPLETE_FILES = range(1, 2+1)
from idlelib import autocomplete_w from idlelib import autocomplete_w
from idlelib.config import idleConf from idlelib.config import idleConf
from idlelib.hyperparser import HyperParser from idlelib.hyperparser import HyperParser
import __main__
# This string includes all chars that may be in an identifier. # This string includes all chars that may be in an identifier.
# TODO Update this here and elsewhere. # TODO Update this here and elsewhere.
@ -182,8 +181,7 @@ class AutoComplete:
else: else:
if mode == COMPLETE_ATTRIBUTES: if mode == COMPLETE_ATTRIBUTES:
if what == "": if what == "":
namespace = __main__.__dict__.copy() namespace = {**__builtins__.__dict__, **globals()}
namespace.update(__main__.__builtins__.__dict__)
bigl = eval("dir()", namespace) bigl = eval("dir()", namespace)
bigl.sort() bigl.sort()
if "__all__" in bigl: if "__all__" in bigl:
@ -218,10 +216,8 @@ class AutoComplete:
return smalll, bigl return smalll, bigl
def get_entity(self, name): def get_entity(self, name):
"""Lookup name in a namespace spanning sys.modules and __main.dict__""" "Lookup name in a namespace spanning sys.modules and globals()."
namespace = sys.modules.copy() return eval(name, {**sys.modules, **globals()})
namespace.update(__main__.__dict__)
return eval(name, namespace)
AutoComplete.reload() AutoComplete.reload()

View file

@ -12,7 +12,6 @@ import types
from idlelib import calltip_w from idlelib import calltip_w
from idlelib.hyperparser import HyperParser from idlelib.hyperparser import HyperParser
import __main__
class Calltip: class Calltip:
@ -100,13 +99,12 @@ class Calltip:
def get_entity(expression): def get_entity(expression):
"""Return the object corresponding to expression evaluated """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: if expression:
namespace = sys.modules.copy() namespace = {**sys.modules, **globals()}
namespace.update(__main__.__dict__)
try: try:
return eval(expression, namespace) return eval(expression, namespace) # Only protect user code.
except BaseException: except BaseException:
# An uncaught exception closes idle, and eval can raise any # An uncaught exception closes idle, and eval can raise any
# exception, especially if user classes are involved. # exception, especially if user classes are involved.

View file

@ -0,0 +1 @@
Use dict unpacking in idlelib and remove unneeded __main__ imports.