From 96bc410fec30d96960f7613331c43ed3f28c526d Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 22 Dec 2025 09:18:28 +0100 Subject: [PATCH] [3.13] gh-143046: Make asyncio REPL respect the `-q` flag (quiet mode) (GH-143047) (#143061) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gh-143046: Make asyncio REPL respect the `-q` flag (quiet mode) (GH-143047) (cherry picked from commit 6213a512bf42464e35ae5090358b80aaa64904cc) Co-authored-by: Bartosz Sławecki --- Lib/asyncio/__main__.py | 17 +++++++++-------- Lib/test/test_repl.py | 6 ++++++ ...25-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index 62f65192df70..e1b9026dd57d 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -84,14 +84,15 @@ class REPLThread(threading.Thread): global return_code try: - banner = ( - f'asyncio REPL {sys.version} on {sys.platform}\n' - f'Use "await" directly instead of "asyncio.run()".\n' - f'Type "help", "copyright", "credits" or "license" ' - f'for more information.\n' - ) - - console.write(banner) + if not sys.flags.quiet: + banner = ( + f'asyncio REPL {sys.version} on {sys.platform}\n' + f'Use "await" directly instead of "asyncio.run()".\n' + f'Type "help", "copyright", "credits" or "license" ' + f'for more information.\n' + ) + + console.write(banner) if startup_path := os.getenv("PYTHONSTARTUP"): sys.audit("cpython.run_startup", startup_path) diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py index 58bd2b5d9168..17bc53d20c39 100644 --- a/Lib/test/test_repl.py +++ b/Lib/test/test_repl.py @@ -409,6 +409,12 @@ class TestAsyncioREPL(unittest.TestCase): expected = "toplevel contextvar test: ok" self.assertIn(expected, output, expected) + def test_quiet_mode(self): + p = spawn_repl("-q", "-m", "asyncio", custom=True) + output = kill_python(p) + self.assertEqual(p.returncode, 0) + self.assertEqual(output[:3], ">>>") + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Library/2025-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst b/Misc/NEWS.d/next/Library/2025-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst new file mode 100644 index 000000000000..ac819a47f4cd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst @@ -0,0 +1,2 @@ +The :mod:`asyncio` REPL no longer prints copyright and version messages in +the quiet mode (:option:`-q`). Patch by Bartosz Sławecki. -- 2.47.3