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
21 changes: 12 additions & 9 deletions Lib/idlelib/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,18 @@ def fetch_completions(self, what, mode):
else:
if mode == ATTRS:
if what == "": # Main module names.
namespace = {**__main__.__builtins__.__dict__,
**__main__.__dict__}
bigl = eval("dir()", namespace)
bigl.extend(completion_kwds)
bigl.sort()
if "__all__" in bigl:
smalll = sorted(eval("__all__", namespace))
else:
smalll = [s for s in bigl if s[:1] != '_']
try:
namespace = {**__main__.__builtins__.__dict__,
**__main__.__dict__}
bigl = eval("dir()", namespace)
bigl.extend(completion_kwds)
bigl.sort()
if "__all__" in bigl:
smalll = sorted(eval("__all__", namespace))
else:
smalll = [s for s in bigl if s[:1] != '_']
except Exception: # a broken __all__ must not abort completion
return [], []
else:
try:
entity = self.get_entity(what)
Expand Down
9 changes: 9 additions & 0 deletions Lib/idlelib/idle_test/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ def _listdir(path):
self.assertEqual(s, ['monty', 'python'])
self.assertEqual(b, ['.hidden', 'monty', 'python'])

def test_fetch_completions_bad_all(self):
# gh-153506: a non-iterable __main__.__all__ must not abort
# module-name completion at an empty prefix.
acp = self.autocomplete
with patch.dict('__main__.__dict__', {'__all__': None}):
self.assertEqual(acp.fetch_completions('', ac.ATTRS), ([], []))
# A valid namespace still yields real completions.
self.assertIn('__name__', acp.fetch_completions('', ac.ATTRS)[1])

def test_get_entity(self):
# Test that a name is in the namespace of sys.modules and
# __main__.__dict__.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IDLE no longer fails to show module-name completions when the interactive
namespace has a non-iterable ``__all__``.
Loading