Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Lib/idlelib/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

class AutoComplete:

def __init__(self, editwin=None, tags=None):
def __init__(self, editwin=None, tags=None, namespace=None):

self.editwin = editwin
self.namespace = namespace
if editwin is not None: # not in subprocess or no-gui test
self.text = editwin.text
self.tags = tags
Expand Down Expand Up @@ -217,8 +219,17 @@ 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__."
return eval(name, {**sys.modules, **__main__.__dict__})
"""Evaluate an expression in a the execution namespace."""
namespace = self.namespace
if namespace is None:
try:
# Fallback when running without a subprocess.
namespace = self.editwin.flist.pyshell.interp.locals
except AttributeError:
# Fallback when there isn't a running shell.
namespace = {**sys.modules, **__main__.__dict__}

return eval(name, namespace)


AutoComplete.reload()
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def __init__(self, rpchandler):
if idlelib.testing is False:
self.locals = __main__.__dict__
self.calltip = calltip.Calltip()
self.autocomplete = autocomplete.AutoComplete()
self.autocomplete = autocomplete.AutoComplete(namespace=self.locals)
else:
self.locals = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the namespace used for completions to be that of the running shell, when
a shell window exists.