From c00d96ccf970c70fe55e97bfdd9a1ca03f680cbb Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 30 Oct 2026 05:20:23 +0800 Subject: [PATCH 1/2] [3.14] gh-139105: Correct the EOF key shown on Windows in `sqlite3`'s `.help` (GH-139106) (cherry picked from commit 7515b64aa7231e8a8cf5271155829a208d789583) Co-authored-by: Keming Signed-off-by: Keming Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Stan Ulbrych --- Lib/sqlite3/__main__.py | 13 ++++++++----- Lib/test/test_sqlite3/test_cli.py | 4 +++- .../2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 4ccf292ddf211c..dd17cea35b3aa8 100644 --- a/Lib/sqlite3/__main__.py +++ b/Lib/sqlite3/__main__.py @@ -12,6 +12,13 @@ from textwrap import dedent +# IDLE uses CTRL-D for EOF on all platforms (gh-102628). +if sys.platform == "win32" and "idlelib.run" not in sys.modules: + EOF_KEY = "CTRL-Z" +else: + EOF_KEY = "CTRL-D" + + def execute(c, sql, suppress_errors=True): """Helper that wraps execution of SQL code. @@ -102,16 +109,12 @@ def main(*args): db_name = repr(args.filename) # Prepare REPL banner and prompts. - if sys.platform == "win32" and "idlelib.run" not in sys.modules: - eofkey = "CTRL-Z" - else: - eofkey = "CTRL-D" banner = dedent(f""" sqlite3 shell, running on SQLite version {sqlite3.sqlite_version} Connected to {db_name} Each command will be run using execute() on the cursor. - Type ".help" for more information; type ".quit" or {eofkey} to quit. + Type ".help" for more information; type ".quit" or {EOF_KEY} to quit. """).strip() sys.ps1 = "sqlite> " sys.ps2 = " ... " diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index a03d7cbe16ba84..b55005383235c5 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -1,5 +1,6 @@ """sqlite3 CLI tests.""" import sqlite3 +import sys import unittest from sqlite3.__main__ import main as cli @@ -73,6 +74,7 @@ class InteractiveSession(unittest.TestCase): MEMORY_DB_MSG = "Connected to a transient in-memory database" PS1 = "sqlite> " PS2 = "... " + EOF_KEY = "CTRL-Z" if sys.platform == "win32" else "CTRL-D" def run_cli(self, *args, commands=()): with ( @@ -95,7 +97,7 @@ def run_cli(self, *args, commands=()): def test_interact(self): out, err = self.run_cli() self.assertIn(self.MEMORY_DB_MSG, err) - self.assertIn(self.MEMORY_DB_MSG, err) + self.assertIn(f'type ".quit" or {self.EOF_KEY} to quit', err) self.assertEndsWith(out, self.PS1) self.assertEqual(out.count(self.PS1), 1) self.assertEqual(out.count(self.PS2), 0) diff --git a/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst b/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst new file mode 100644 index 00000000000000..0494a66b094eee --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst @@ -0,0 +1 @@ +Correct the EOF key shown in the :mod:`sqlite3` CLI ``.help`` text on Windows. From 6dfe17df2cf6cfa20345bec08f188ba57a7656ea Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 30 Oct 2026 11:41:28 +0000 Subject: [PATCH 2/2] Delete Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst --- .../next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst diff --git a/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst b/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst deleted file mode 100644 index 0494a66b094eee..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-09-18-18-03-32.gh-issue-139105.1QQ_W4.rst +++ /dev/null @@ -1 +0,0 @@ -Correct the EOF key shown in the :mod:`sqlite3` CLI ``.help`` text on Windows.