[issue29298] argparse fails with required subparsers, un-named dest, and empty argv
paul j3
report at bugs.python.org
Fri Jan 20 00:38:54 EST 2017
paul j3 added the comment:
http://bugs.python.org/issue9253 argparse: optional subparsers
Initially this bug/issue was a request to allow subparsers to be optional. But with the change in how required actions are handled, subparsers are now optional by default.
As you learned from the SO question you now have to specify
subparsers.required = True
This is also discussed in my post (and following ones)
http://bugs.python.org/issue9253#msg186387
The default 'dest' is SUPPRESS. The error you report occurs because the 'required' error mechanism cannot handle that value. The suggest fix is to assign `dest`, even if it is not needed in the Namespace. For now it is needed for error reporting.
Reviewing my suggested patches, it looks like I generate a 'dest' substitute from the subparser names. So the 'required' error would look like
python: error: the following arguments are required: {cmd1, cmd2}
I think this issue can be closed with a reference to 9253. Or maybe that issue is too old, long and confusing, and we need a new bug/issue.
----------
nosy: +paul.j3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29298>
_______________________________________
More information about the Python-bugs-list
mailing list