From 39ba77783af2eba2ee2571b676698e3e9121eba0 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 12 Jun 2025 16:24:49 +0100 Subject: [PATCH 1/2] Add completion for .commands --- Lib/sqlite3/_completer.py | 9 +++++++-- Lib/test/test_sqlite3/test_cli.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/sqlite3/_completer.py b/Lib/sqlite3/_completer.py index f21ef69cad6439..f67e9a108a01b5 100644 --- a/Lib/sqlite3/_completer.py +++ b/Lib/sqlite3/_completer.py @@ -5,6 +5,8 @@ except ImportError: SQLITE_KEYWORDS = () +SQLITE_KEYWORDS += ('.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 SQLITE_KEYWORDS 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 d993e28c4bb3a6..4a4780196b4c8e 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()" @@ -301,7 +306,7 @@ def test_complete_no_input(self): self.assertEqual(len(indices), 2) start, end = indices candidates = [l.strip() for l in lines[start+1:end]] - self.assertEqual(candidates, sorted(SQLITE_KEYWORDS)) + self.assertEqual(candidates, sorted(SQLITE_KEYWORDS + ('.help', '.quit', '.version'))) except: if verbose: print(' PTY output: '.center(30, '-')) From 82ff87ecc750eb41de0ed269a00cf576c62a4c35 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 22 Aug 2025 10:21:52 +0100 Subject: [PATCH 2/2] Requested changes --- Lib/sqlite3/__main__.py | 1 + Lib/sqlite3/_completer.py | 4 ++-- Lib/test/test_sqlite3/test_cli.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 9e74b49ee828bc..a659c5cf3be8d1 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -60,6 +60,7 @@ def runsource(self, source, filename="", 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 f67e9a108a01b5..b3e8c0e5f36208 100644 --- a/Lib/sqlite3/_completer.py +++ b/Lib/sqlite3/_completer.py @@ -5,7 +5,7 @@ except ImportError: SQLITE_KEYWORDS = () -SQLITE_KEYWORDS += ('.quit', '.help', '.version') +CLI_COMMANDS = ('.quit', '.help', '.version') _completion_matches = [] @@ -15,7 +15,7 @@ def _complete(text, state): if state == 0: if text.startswith('.'): - _completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text)] + _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)] diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 4a4780196b4c8e..dfd89a9b855d36 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -306,7 +306,7 @@ def test_complete_no_input(self): self.assertEqual(len(indices), 2) start, end = indices candidates = [l.strip() for l in lines[start+1:end]] - self.assertEqual(candidates, sorted(SQLITE_KEYWORDS + ('.help', '.quit', '.version'))) + self.assertEqual(candidates, sorted(SQLITE_KEYWORDS)) except: if verbose: print(' PTY output: '.center(30, '-'))