Issue #25663: Make rlcompleter avoid duplicate global names

This commit is contained in:
Martin Panter 2015-11-23 23:50:26 +00:00
parent bf7b9ede1a
commit ed92910852
3 changed files with 29 additions and 2 deletions

View file

@ -103,13 +103,16 @@ class Completer:
"""
import keyword
matches = []
seen = {"__builtins__"}
n = len(text)
for word in keyword.kwlist:
if word[:n] == text:
seen.add(word)
matches.append(word)
for nspace in [builtins.__dict__, self.namespace]:
for nspace in [self.namespace, builtins.__dict__]:
for word, val in nspace.items():
if word[:n] == text and word != "__builtins__":
if word[:n] == text and word not in seen:
seen.add(word)
matches.append(self._callable_postfix(val, word))
return matches