Skip to content

Commit 5773f17

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 2fa2ee8 commit 5773f17

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/sqlite3/_completer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from contextlib import contextmanager
22

33

4-
_keywords = ["ABORT", "ACTION", "ADD", "AFTER", "ALL", "ALTER", "ALWAYS",
4+
_keywords = ("ABORT", "ACTION", "ADD", "AFTER", "ALL", "ALTER", "ALWAYS",
55
"ANALYZE", "AND", "AS", "ASC", "ATTACH", "AUTOINCREMENT",
66
"BEFORE", "BEGIN", "BETWEEN", "BY", "CASCADE", "CASE", "CAST",
77
"CHECK", "COLLATE", "COLUMN", "COMMIT", "CONFLICT",
@@ -25,13 +25,16 @@
2525
"TABLE", "TEMP", "TEMPORARY", "THEN", "TIES", "TO",
2626
"TRANSACTION", "TRIGGER", "UNBOUNDED", "UNION", "UNIQUE",
2727
"UPDATE", "USING", "VACUUM", "VALUES", "VIEW", "VIRTUAL",
28-
"WHEN", "WHERE", "WINDOW", "WITH", "WITHOUT"]
28+
"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 = [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)