New submission from Wolfgang Maier <wolfgang.ma...@biologie.uni-freiburg.de>:

I find the True default for 'required' quite cumbersome introduced as a result 
of issue 26510.

With existing parsers it can unnecessarily break compatibility between 
Python3.x versions only to make porting a bit easier for Python2 users.
I think, this late in the life cycle of Python2, within Python3 compatibility 
should be ranked higher than py2to3 portability.

Command line parsing of a package of mine has long used optional subparsers 
(without me even thinking much about the fact). Now in 3.7, running

python3.7 -m MyPackage

without arguments (the parser is in __main__.py) I get the ill-formatted error 
message:

__main__.py: error: the following arguments are required: 

while my code in 3.3 - 3.6 was catching the empty Namespace returned and 
printed a help message.

Because the 'required' keyword argument did not exist in < 3.7 there was no 
simple way for me to write code that is compatible between all 3.x versions. 
What I ended up doing now is to check sys.argv before trying to parse things, 
then print the help message, when that only has a single item, just to keep my 
existing code working.

OTOH, everything would be just fine with a default value of False.
Also that truncated error message should be fixed before 3.7 gets released.

----------
components: Library (Lib)
messages: 314145
nosy: Anthony Sottile, bethard, eric.araujo, memeplex, paul.j3, wolma
priority: normal
severity: normal
status: open
title: argparse: make new 'required' argument to add_subparsers default to 
False instead of True
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33109>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to