Issue 21966: InteractiveConsole does not support -q option (original) (raw)

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:05 admin set github: 66165
2014-07-12 20:38:01 belopolsky set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2014-07-12 20:36:46 python-dev set nosy: + python-devmessages: +
2014-07-12 19:16:07 anton.barkovsky set files: + code_flags_argparse_v2.patchmessages: +
2014-07-12 19:12:16 belopolsky set messages: +
2014-07-12 19:12:16 anton.barkovsky set messages: +
2014-07-12 19:07:31 belopolsky set messages: +
2014-07-12 19:02:43 anton.barkovsky set files: + code_flags_argparse.patchmessages: +
2014-07-12 18:55:58 belopolsky set messages: +
2014-07-12 18:50:38 anton.barkovsky set messages: +
2014-07-12 18:44:07 r.david.murray set nosy: + r.david.murraymessages: +
2014-07-12 18:32:11 belopolsky set components: + Library (Lib)
2014-07-12 18:30:39 belopolsky set versions: + Python 3.5nosy: + benjamin.petersonmessages: + assignee: belopolskystage: commit review
2014-07-12 18:17:52 anton.barkovsky set files: + code.patchnosy: + anton.barkovskymessages: + keywords: + patch
2014-07-12 16:05:23 belopolsky create