This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: InteractiveConsole does not support -q option
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: anton.barkovsky, belopolsky, benjamin.peterson, python-dev, r.david.murray
Priority: normal Keywords: easy, patch

Created on 2014-07-12 16:05 by belopolsky, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
code.patch anton.barkovsky, 2014-07-12 18:17 review
code_flags_argparse.patch anton.barkovsky, 2014-07-12 19:02 review
code_flags_argparse_v2.patch anton.barkovsky, 2014-07-12 19:16 review
Messages (13)
msg222850 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 16:05
When invoked with -q option, python3 prints no banner:
$ python3 -q
>>>

However, code.InteractiveConsole does not implement this feature:
$ python3 -mcode -q
Python 3.4.1 (default, May 19 2014, 13:10:29)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
msg222862 - (view) Author: Anton Barkovsky (anton.barkovsky) * Date: 2014-07-12 18:17
Here's a patch.
msg222863 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 18:30
That was quick! (Well - I knew it would not be hard.)

I have two questions:

1. How should python3 -q -mcode behave?
2. If we add this patch, should we also attempt to emulate other command line options (-V, -h, etc.)?
msg222865 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-07-12 18:44
Whether or not other options are emulated, unimplemented ones should probably be rejected.
msg222866 - (view) Author: Anton Barkovsky (anton.barkovsky) * Date: 2014-07-12 18:50
> 1. How should python3 -q -mcode behave?

I've only now found out about sys.flags. I think we should check for -q both before -m and after, because why not?

> 2. If we add this patch, should we also attempt to emulate other command line options (-V, -h, etc.)?

As I see it, the module is only concerned with REPL functionality, making these options a bit out of scope.
msg222867 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 18:55
In order to implement reasonable rejection behavior, we probably need to add some support for -h.

$ python3 -z
Unknown option: -z
usage: python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

I don't think we should condition acceptance of this patch on extra features.

AFAICT, the main use of the code module is in embedded situations and the if __name__ == "__main__" behavior is mostly there for demonstration purposes.

On the other hand, something like

$ python3 -mcode -z
Unknown option: -z
usage: python3 -mcode [-q]

is not hard to implement.
msg222868 - (view) Author: Anton Barkovsky (anton.barkovsky) * Date: 2014-07-12 19:02
Here's a patch that checks both sys.flags and sys.argv and uses argparse.
msg222869 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 19:07
> I think we should check for -q both before -m and after, because why not?

If we check for sys.flags.quiet, wouldn't it be surprising to have

$ python3 -mcode -q
>>> import sys; sys.flags.quiet
0
msg222870 - (view) Author: Anton Barkovsky (anton.barkovsky) * Date: 2014-07-12 19:12
That's not a very likely scenario and I think the distinction between arguments that are passed to the script and interpreter flags is fairly obvious.
msg222871 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 19:12
A nitpick: banner=banner in 

+   interact(banner=banner)

is redundant.

+   interact(banner)

would work and is just as clear.
msg222872 - (view) Author: Anton Barkovsky (anton.barkovsky) * Date: 2014-07-12 19:16
Yeah, my love for keyword arguments is a bit too big sometimes.
msg222880 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-12 20:36
New changeset 7f8843ec34ee by Alexander Belopolsky in branch 'default':
Issue #21966: Respect -q command-line option when code module is ran.
http://hg.python.org/cpython/rev/7f8843ec34ee
msg222882 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-07-12 20:38
Committed.  Thanks, Anton.
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 66165
2014-07-12 20:38:01belopolskysetstatus: open -> closed
resolution: fixed
messages: + msg222882

stage: commit review -> resolved
2014-07-12 20:36:46python-devsetnosy: + python-dev
messages: + msg222880
2014-07-12 19:16:07anton.barkovskysetfiles: + code_flags_argparse_v2.patch

messages: + msg222872
2014-07-12 19:12:16belopolskysetmessages: + msg222871
2014-07-12 19:12:16anton.barkovskysetmessages: + msg222870
2014-07-12 19:07:31belopolskysetmessages: + msg222869
2014-07-12 19:02:43anton.barkovskysetfiles: + code_flags_argparse.patch

messages: + msg222868
2014-07-12 18:55:58belopolskysetmessages: + msg222867
2014-07-12 18:50:38anton.barkovskysetmessages: + msg222866
2014-07-12 18:44:07r.david.murraysetnosy: + r.david.murray
messages: + msg222865
2014-07-12 18:32:11belopolskysetcomponents: + Library (Lib)
2014-07-12 18:30:39belopolskysetversions: + Python 3.5
nosy: + benjamin.peterson

messages: + msg222863

assignee: belopolsky
stage: commit review
2014-07-12 18:17:52anton.barkovskysetfiles: + code.patch

nosy: + anton.barkovsky
messages: + msg222862

keywords: + patch
2014-07-12 16:05:23belopolskycreate