From 6b59a0ba98cde196053fd2d064e8bd905c922b59 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 10 May 2025 08:34:06 +0100 Subject: [PATCH 1/9] Fixup pr --- Lib/sqlite3/__main__.py | 4 ++-- Lib/test/test_sqlite3/test_cli.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 4ccf292ddf211c..2f6b770ecd040b 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -61,8 +61,8 @@ def runsource(self, source, filename="", symbol="single"): case "": pass case _ as unknown: - self.write("Error: unknown command or invalid arguments:" - f' "{unknown}".\n') + print("Error: unknown command or invalid arguments:" + f' "{unknown}"', file=sys.stderr) else: if not sqlite3.complete_statement(source): return True diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index a03d7cbe16ba84..7fdbfa1f4736d8 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -129,7 +129,7 @@ def test_interact_dot_commands_unknown(self): self.assertEndsWith(out, self.PS1) self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS2), 0) - self.assertIn("Error", err) + self.assertIn("Error: unknown command or invalid arguments", err) # test "unknown_command" is pointed out in the error message self.assertIn("unknown_command", err) From 6cb043254fbdf9b7cdba28d3a112aab65dd41cf5 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 10 May 2025 09:23:16 +0100 Subject: [PATCH 2/9] Benedikts suggestion --- Lib/sqlite3/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 711cbceb55d606..fb9c0f1b7b41c5 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -61,7 +61,7 @@ def runsource(self, source, filename="", symbol="single"): if source[0] == ".": match source[1:].strip(): case "version": - print(f"{sqlite3.sqlite_version}") + print(sqlite3.sqlite_version) case "help": print("Enter SQL code and press enter.") case "quit": From 1c6cf80993f87316c5665134d50f4c6ce791bf6d Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 10 May 2025 09:33:57 +0100 Subject: [PATCH 3/9] Update Lib/sqlite3/__main__.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/sqlite3/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index fb9c0f1b7b41c5..3504b6e0730663 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -71,7 +71,8 @@ def runsource(self, source, filename="", symbol="single"): case _ as unknown: t = theme.traceback print(f'{t.type}Error{t.reset}:{t.message} unknown command ' - f'or invalid arguments: "{unknown}"{t.reset}', file=sys.stderr) + f'or invalid arguments: "{unknown}"{t.reset}', + file=sys.stderr) else: if not sqlite3.complete_statement(source): return True From 97d002d357d55e9ecf56213b7d01223e26bb1a48 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 13 Jun 2025 18:06:34 +0100 Subject: [PATCH 4/9] Use rstrip --- Lib/sqlite3/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 3504b6e0730663..b44fd78060ce2a 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -59,7 +59,7 @@ def runsource(self, source, filename="", symbol="single"): if not source or source.isspace(): return False if source[0] == ".": - match source[1:].strip(): + match source[1:].rstrip(): case "version": print(sqlite3.sqlite_version) case "help": From c2ed7f108fe17a33ac90c1e7d7b70b2ebbf5baa0 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 13 Jun 2025 18:33:03 +0100 Subject: [PATCH 5/9] Adding the test file would be a good idea --- Lib/test/test_sqlite3/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 0494a04e54eb5d..2852d8d19f0699 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -142,11 +142,11 @@ def test_interact_dot_commands_empty(self): self.assertEqual(out.count(self.PS2), 0) def test_interact_dot_commands_with_whitespaces(self): - out, err = self.run_cli(commands=(".version ", ". version")) + out, err = self.run_cli(commands=(".version ",)) self.assertIn(self.MEMORY_DB_MSG, err) - self.assertEqual(out.count(sqlite3.sqlite_version + "\n"), 2) + self.assertIn(sqlite3.sqlite_version, out) self.assertEndsWith(out, self.PS1) - self.assertEqual(out.count(self.PS1), 3) + self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS2), 0) def test_interact_valid_sql(self): From 7170ad9bed387cc2847e277e6a6950d194f0d04c Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 13 Jun 2025 18:33:26 +0100 Subject: [PATCH 6/9] Revert "Use rstrip" This reverts commit 97d002d357d55e9ecf56213b7d01223e26bb1a48. --- Lib/sqlite3/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index b44fd78060ce2a..3504b6e0730663 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -59,7 +59,7 @@ def runsource(self, source, filename="", symbol="single"): if not source or source.isspace(): return False if source[0] == ".": - match source[1:].rstrip(): + match source[1:].strip(): case "version": print(sqlite3.sqlite_version) case "help": From fed7c0a6d639ee66fb2cbf62d1dac59117e6254b Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 13 Jun 2025 18:33:30 +0100 Subject: [PATCH 7/9] Revert "Adding the test file would be a good idea" This reverts commit c2ed7f108fe17a33ac90c1e7d7b70b2ebbf5baa0. --- Lib/test/test_sqlite3/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 2852d8d19f0699..0494a04e54eb5d 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -142,11 +142,11 @@ def test_interact_dot_commands_empty(self): self.assertEqual(out.count(self.PS2), 0) def test_interact_dot_commands_with_whitespaces(self): - out, err = self.run_cli(commands=(".version ",)) + out, err = self.run_cli(commands=(".version ", ". version")) self.assertIn(self.MEMORY_DB_MSG, err) - self.assertIn(sqlite3.sqlite_version, out) + self.assertEqual(out.count(sqlite3.sqlite_version + "\n"), 2) self.assertEndsWith(out, self.PS1) - self.assertEqual(out.count(self.PS1), 2) + self.assertEqual(out.count(self.PS1), 3) self.assertEqual(out.count(self.PS2), 0) def test_interact_valid_sql(self): From e8fde8d1dc78b631ce9843abf425312a3621e098 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 14 Jun 2025 13:37:53 +0300 Subject: [PATCH 8/9] Apply suggestions from code review --- Lib/sqlite3/__main__.py | 5 ++--- Lib/test/test_sqlite3/test_cli.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 3504b6e0730663..f8a995dcd4ccf6 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -70,9 +70,8 @@ def runsource(self, source, filename="", symbol="single"): pass case _ as unknown: t = theme.traceback - print(f'{t.type}Error{t.reset}:{t.message} unknown command ' - f'or invalid arguments: "{unknown}"{t.reset}', - file=sys.stderr) + self.write(f'{t.type}Error{t.reset}: {t.message}unknown ' + f'command: "{unknown}"{t.reset}\n') else: if not sqlite3.complete_statement(source): return True diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 0494a04e54eb5d..23580dbebdb9d1 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -130,7 +130,7 @@ def test_interact_dot_commands_unknown(self): self.assertEndsWith(out, self.PS1) self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS2), 0) - self.assertIn("Error: unknown command or invalid arguments", err) + self.assertIn('Error: unknown command "', err) # test "unknown_command" is pointed out in the error message self.assertIn("unknown_command", err) From 4dcd3791549c6421a4be890821ffcd96acec8252 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 14 Jun 2025 13:38:44 +0300 Subject: [PATCH 9/9] Update Lib/test/test_sqlite3/test_cli.py --- Lib/test/test_sqlite3/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 23580dbebdb9d1..112501b05f2c06 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -130,7 +130,7 @@ def test_interact_dot_commands_unknown(self): self.assertEndsWith(out, self.PS1) self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS2), 0) - self.assertIn('Error: unknown command "', err) + self.assertIn('Error: unknown command: "', err) # test "unknown_command" is pointed out in the error message self.assertIn("unknown_command", err)