Skip to content

Commit 96bc410

Browse files
[3.13] gh-143046: Make asyncio REPL respect the -q flag (quiet mode) (GH-143047) (#143061)
gh-143046: Make asyncio REPL respect the `-q` flag (quiet mode) (GH-143047) (cherry picked from commit 6213a51) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
1 parent c084a66 commit 96bc410

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Lib/asyncio/__main__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ def run(self):
8484
global return_code
8585

8686
try:
87-
banner = (
88-
f'asyncio REPL {sys.version} on {sys.platform}\n'
89-
f'Use "await" directly instead of "asyncio.run()".\n'
90-
f'Type "help", "copyright", "credits" or "license" '
91-
f'for more information.\n'
92-
)
93-
94-
console.write(banner)
87+
if not sys.flags.quiet:
88+
banner = (
89+
f'asyncio REPL {sys.version} on {sys.platform}\n'
90+
f'Use "await" directly instead of "asyncio.run()".\n'
91+
f'Type "help", "copyright", "credits" or "license" '
92+
f'for more information.\n'
93+
)
94+
95+
console.write(banner)
9596

9697
if startup_path := os.getenv("PYTHONSTARTUP"):
9798
sys.audit("cpython.run_startup", startup_path)

Lib/test/test_repl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ def test_toplevel_contextvars_async(self):
409409
expected = "toplevel contextvar test: ok"
410410
self.assertIn(expected, output, expected)
411411

412+
def test_quiet_mode(self):
413+
p = spawn_repl("-q", "-m", "asyncio", custom=True)
414+
output = kill_python(p)
415+
self.assertEqual(p.returncode, 0)
416+
self.assertEqual(output[:3], ">>>")
417+
412418

413419
if __name__ == "__main__":
414420
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :mod:`asyncio` REPL no longer prints copyright and version messages in
2+
the quiet mode (:option:`-q`). Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)