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
7 changes: 3 additions & 4 deletions Lib/_pyrepl/fancycompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# All Rights Reserved
"""Colorful tab completion for Python prompt"""
from _colorize import ANSIColors, get_colors, get_theme
import builtins
import rlcompleter
import keyword
import types
Expand Down Expand Up @@ -112,10 +113,8 @@ def global_matches(self, text):
if keyword.iskeyword(clean_name) or keyword.issoftkeyword(clean_name):
values.append(None)
else:
try:
values.append(eval(name, self.namespace))
except Exception:
values.append(None)
values.append(self.namespace.get(
clean_name, builtins.__dict__.get(clean_name)))
if self.use_colors and names:
return self.colorize_matches(names, values)
return names
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pyrepl/test_fancycompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_module_attributes_do_not_reify_lazy_imports(self):
self.assertEqual(compl.attr_matches(f"{name}.j"), [f"{name}.json"])
self.assertIs(type(module.__dict__["json"]), types.LazyImportType)

def test_globals_do_not_reify_lazy_imports(self):
namespace = {}
exec("lazy import json\nlazy import jsonz_missing\n", namespace)
compl = Completer(namespace, use_colors=True)
self.assertEqual(len(compl.global_matches("json")), 2)
self.assertIs(type(namespace["json"]), types.LazyImportType)

def test_complete_colored_single_match(self):
"""No coloring, via commonprefix."""
compl = Completer({'foobar': 42}, use_colors=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tab completion of global names in the :term:`REPL` no longer imports
lazily imported modules.
Loading