msg222850 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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)  |
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) *  |
Date: 2014-07-12 20:38 |
Committed. Thanks, Anton. |
|
|