classification
Title: [argparse] Add required argument to add_subparsers
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: merwok Nosy List: Anthony Sottile, bethard, memeplex, merwok, paul.j3
Priority: normal Keywords:

Created on 2016-03-08 13:56 by memeplex, last changed 2017-09-20 21:36 by merwok. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3027 merged Anthony Sottile, 2017-08-08 18:02
Messages (4)
msg261358 - (view) Author: Memeplex (memeplex) Date: 2016-03-08 13:56
It's useful in combination with dest. Currently you have to set required as an attribute. This is not only inconsistent but not even documented as a valid usage (in general, it's not clear from the docs whether attribute setting -vs argument passing- is a valid usage).
msg261535 - (view) Author: paul j3 (paul.j3) * Date: 2016-03-11 00:01
This has been raised before.  I think

http://bugs.python.org/issue9253

is the correct issue.

It used to be that 'subparsers' were required.  But there was a change in how 'required' arguments were tested, and 'subparsers' fell through the cracks.  Now subparsers are optional (at least the parser doesn't raise an error).  The temporary fix is to set the 'required' attribute after creation.

I proposed that the default be 'required=True', and that we be allowed to set the parameter.  But that patch, like many others, has languished.
msg300282 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2017-08-15 03:23
I've added a patch for this https://github.com/python/cpython/pull/3027

Would love to get a review so it could be included
msg302660 - (view) Author: Éric Araujo (merwok) * (Python committer) Date: 2017-09-20 21:35
New changeset aaf6fc0982c916cb71d9e0afcd7dda4ba495793b by Éric Araujo (Anthony Sottile) in branch 'master':
bpo-26510: make argparse subparsers required by default (#3027)
https://github.com/python/cpython/commit/aaf6fc0982c916cb71d9e0afcd7dda4ba495793b
History
Date User Action Args
2017-09-20 21:37:05merwoklinkissue9253 dependencies
2017-09-20 21:36:42merwoksetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2017-09-20 21:35:29merwoksetmessages: + msg302660
2017-09-20 17:26:40merwoksetassignee: merwok
stage: commit review

nosy: + merwok
versions: + Python 3.7, - Python 3.5
2017-08-15 03:23:46Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg300282
2017-08-08 18:02:02Anthony Sottilesetpull_requests: + pull_request3061
2016-03-11 00:01:03paul.j3setnosy: + paul.j3
messages: + msg261535
2016-03-08 13:58:22memeplexsetnosy: + bethard
2016-03-08 13:56:53memeplexsettitle: Add required argument to add_subparsers -> [argparse] Add required argument to add_subparsers
2016-03-08 13:56:01memeplexcreate