Skip to content

Commit f179be1

Browse files
committed
Avoid regeneration of candidates. Store them when state is 0 and returns
them one by one on subsequent calls http://tiswww.case.edu/php/chet/readline/readline.html#How-Completing-Works > *state* is zero the first time the function is called, allowing the > generator to perform any necessary initialization, and a positive > non-zero integer for each subsequent call. Usually the generator > function computes the list of possible completions when *state* is zero, > and returns them one at a time on subsequent calls.
1 parent 22652ae commit f179be1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/sqlite3/_completer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
"UPDATE", "USING", "VACUUM", "VALUES", "VIEW", "VIRTUAL",
2828
"WHEN", "WHERE", "WINDOW", "WITH", "WITHOUT"]
2929

30+
_completion_matches = ()
3031

3132
def _complete(text, state):
32-
options = [c + " " for c in _keywords if c.startswith(text.upper())]
33+
global _completion_matches
34+
if state == 0:
35+
_completion_matches = tuple(c + " " for c in _keywords if c.startswith(text.upper()))
3336
try:
34-
return options[state]
37+
return _completion_matches[state]
3538
except IndexError:
3639
return None
3740

0 commit comments

Comments
 (0)