Skip to content
Next Next commit
bpo-37765: Add keywords to IDLE's main completion list
  • Loading branch information
terryjreedy committed Aug 5, 2019
commit 15b9ba01342884283e704cedbe85424e9f031512
2 changes: 2 additions & 0 deletions Lib/idlelib/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pop up a list of candidates.
"""
import __main__
import keyword
import os
import string
import sys
Expand Down Expand Up @@ -175,6 +176,7 @@ def fetch_completions(self, what, mode):
namespace = {**__main__.__builtins__.__dict__,
**__main__.__dict__}
bigl = eval("dir()", namespace)
bigl.extend(keyword.kwlist)
Comment thread
terryjreedy marked this conversation as resolved.
Outdated
bigl.sort()
if "__all__" in bigl:
smalll = sorted(eval("__all__", namespace))
Expand Down
5 changes: 3 additions & 2 deletions Lib/idlelib/idle_test/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ def test_fetch_completions(self):
with patch.dict('__main__.__dict__', {'__all__': ['a', 'b']}):
s, b = acp.fetch_completions('', ac.ATTRS)
self.assertEqual(s, ['a', 'b'])
self.assertIn('__name__', b) # From __main__.__dict__
self.assertIn('sum', b) # From __main__.__builtins__.__dict__
self.assertIn('__name__', b) # From __main__.__dict__.
self.assertIn('sum', b) # From __main__.__builtins__.__dict__.
self.assertIn('and', b) # From keyword.kwlist.

# Test attributes with name entity.
mock = Mock()
Expand Down