https://github.com/python/cpython/commit/a5530656c152c1e7755d3d219f5b8b72f0f21479
commit: a5530656c152c1e7755d3d219f5b8b72f0f21479
branch: main
author: Stan Ulbrych <[email protected]>
committer: encukou <[email protected]>
date: 2025-08-25T14:58:00+02:00
summary:
gh-133390: Extend completion for .commands in `sqlite3` (GH-135432)
files:
M Lib/sqlite3/__main__.py
M Lib/sqlite3/_completer.py
M Lib/test/test_sqlite3/test_cli.py
diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py
index 35344ecceff526..093b38c0001387 100644
--- a/Lib/sqlite3/__main__.py
+++ b/Lib/sqlite3/__main__.py
@@ -60,6 +60,7 @@ def runsource(self, source, filename="<input>",
symbol="single"):
if not source or source.isspace():
return False
+ # Remember to update CLI_COMMANDS in _completer.py
if source[0] == ".":
match source[1:].strip():
case "version":
diff --git a/Lib/sqlite3/_completer.py b/Lib/sqlite3/_completer.py
index f21ef69cad6439..b3e8c0e5f36208 100644
--- a/Lib/sqlite3/_completer.py
+++ b/Lib/sqlite3/_completer.py
@@ -5,6 +5,8 @@
except ImportError:
SQLITE_KEYWORDS = ()
+CLI_COMMANDS = ('.quit', '.help', '.version')
+
_completion_matches = []
@@ -12,8 +14,11 @@ def _complete(text, state):
global _completion_matches
if state == 0:
- text_upper = text.upper()
- _completion_matches = [c for c in SQLITE_KEYWORDS if
c.startswith(text_upper)]
+ if text.startswith('.'):
+ _completion_matches = [c for c in CLI_COMMANDS if
c.startswith(text)]
+ else:
+ text_upper = text.upper()
+ _completion_matches = [c for c in SQLITE_KEYWORDS if
c.startswith(text_upper)]
try:
return _completion_matches[state] + " "
except IndexError:
diff --git a/Lib/test/test_sqlite3/test_cli.py
b/Lib/test/test_sqlite3/test_cli.py
index 720fa3c4c1ea8b..5926cec0569ddb 100644
--- a/Lib/test/test_sqlite3/test_cli.py
+++ b/Lib/test/test_sqlite3/test_cli.py
@@ -249,6 +249,11 @@ def test_complete_sql_keywords(self):
self.assertIn(b"SELECT", output)
self.assertIn(b"(1,)", output)
+ # .commands are completed without changing case
+ input_ = b".ver\t\n.quit\n"
+ output = self.write_input(input_)
+ self.assertIn(b".version", output)
+
@unittest.skipIf(sys.platform.startswith("freebsd"),
"Two actual tabs are inserted when there are no matching"
" completions in the pseudo-terminal opened by run_pty()"
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]