Skip to content

Commit 3a98ff9

Browse files
committed
Issue #21966: Respect -q command-line option when code module is ran.
Contributed by Anton Barkovsky.
1 parent 3db27b7 commit 3a98ff9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/code.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import sys
99
import traceback
10+
import argparse
1011
from codeop import CommandCompiler, compile_command
1112

1213
__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
@@ -299,4 +300,12 @@ def interact(banner=None, readfunc=None, local=None):
299300

300301

301302
if __name__ == "__main__":
302-
interact()
303+
parser = argparse.ArgumentParser()
304+
parser.add_argument('-q', action='store_true',
305+
help="don't print version and copyright messages")
306+
args = parser.parse_args()
307+
if args.q or sys.flags.quiet:
308+
banner = ''
309+
else:
310+
banner = None
311+
interact(banner)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Core and Builtins
108108
Library
109109
-------
110110

111+
- Issue #21966: Respect -q command-line option when code module is ran.
112+
111113
- Issue #19076: Don't pass the redundant 'file' argument to self.error().
112114

113115
- Issue #16382: Improve exception message of warnings.warn() for bad

0 commit comments

Comments
 (0)