https://github.com/python/cpython/commit/5e4a594619c9aa80204825131eec3997c7a9f0b9 commit: 5e4a594619c9aa80204825131eec3997c7a9f0b9 branch: 3.14 author: Stan Ulbrych <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-10-30T12:10:19Z summary:
[3.14] gh-139105: Correct the EOF key shown on Windows in `sqlite3`'s `.help` (GH-139106) (#160966) (cherry picked from commit 7515b64aa7231e8a8cf5271155829a208d789583) Co-authored-by: Keming <[email protected]> Signed-off-by: Keming <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> files: M Lib/sqlite3/__main__.py M Lib/test/test_sqlite3/test_cli.py diff --git a/Lib/sqlite3/__main__.py b/Lib/sqlite3/__main__.py index 4ccf292ddf211c2..dd17cea35b3aa8a 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 a03d7cbe16ba847..b55005383235c52 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) _______________________________________________ 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]
