Skip to content

Commit 6213a51

Browse files
authored
gh-143046: Make asyncio REPL respect the -q flag (quiet mode) (#143047)
1 parent 09044dd commit 6213a51

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
@@ -86,14 +86,15 @@ def run(self):
8686
global return_code
8787

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

9899
if startup_path := os.getenv("PYTHONSTARTUP"):
99100
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)