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

Created on 2016-03-08 13:56 by memeplex, last changed 2018-05-16 19:51 by ned.deily. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3027 merged Anthony Sottile, 2017-08-08 18:02
PR 6919 open ned.deily, 2018-05-16 19:51
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

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

Would love to get a review so it could be included
msg302660 - (view) Author: Éric Araujo (eric.araujo) * (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)
Date User Action Args
2018-05-16 19:51:40ned.deilysetpull_requests: + pull_request6588
2017-09-20 21:37:05eric.araujolinkissue9253 dependencies
2017-09-20 21:36:42eric.araujosetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2017-09-20 21:35:29eric.araujosetmessages: + msg302660
2017-09-20 17:26:40eric.araujosetassignee: eric.araujo
stage: commit review

nosy: + eric.araujo
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