Skip to content

Commit d2d236d

Browse files
committed
Keep a frozen copy of keyword list
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent b454048 commit d2d236d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bpython/autocomplete.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"div", "truediv", "neg", "pos", "abs", "invert", "complex", "int", "float",
5454
"oct", "hex", "index", "coerce", "enter", "exit"))
5555

56+
if py3:
57+
KEYWORDS = frozenset(keyword.kwlist)
58+
else:
59+
KEYWORDS = frozenset(name.decode('ascii') for name in keyword.kwlist)
60+
5661

5762
def after_last_dot(name):
5863
return name.rstrip('.').rsplit('.')[-1]
@@ -284,10 +289,8 @@ def matches(self, cursor_offset, line, **kwargs):
284289

285290
matches = set()
286291
n = len(text)
287-
for word in keyword.kwlist:
292+
for word in KEYWORDS:
288293
if method_match(word, n, text):
289-
if not py3:
290-
word = word.decode('ascii') # py2 keywords are all ascii
291294
matches.add(word)
292295
for nspace in [builtins.__dict__, locals_]:
293296
for word, val in nspace.items():

0 commit comments

Comments
 (0)