]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-143046: Make asyncio REPL respect the `-q` flag (quiet mode) (#143047)
authorBartosz Sławecki <bartosz@ilikepython.com>
Mon, 22 Dec 2025 07:05:15 +0000 (08:05 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Dec 2025 07:05:15 +0000 (07:05 +0000)
Lib/asyncio/__main__.py
Lib/test/test_repl.py
Misc/NEWS.d/next/Library/2025-12-21-17-44-28.gh-issue-143046.GBa5Ip.rst [new file with mode: 0644]

index 89d456b6858c07f3814c6bf8d243ff9bdec4e458..afbb70bbcab930321e1c002460e95bdddabff626 100644 (file)
@@ -86,14 +86,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)
index 042aa84b35dcf8cc4fd5ef7311c712c2398e7d93..0fa1df40e44c5f6c5564c48e0ec31bbf7fb73335 100644 (file)
@@ -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 (file)
index 0000000..ac819a4
--- /dev/null
@@ -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.