Author paul.j3
Recipients Anthony Sottile, DasIch, G2P, Julian, Mariatta, bethard, bewest, bkabrda, chris.jerdonek, couplewavylines, csernazs, derks, dsully, elsdoerfer, eric.araujo, frispete, jwilk, labrat, nvie, paul.j3, r.david.murray, seblu, svilgelm, zzzeek
Date 2017-10-18.18:58:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508353121.75.0.213398074469.issue9253@psf.upfronthosting.co.za>
In-reply-to
Content
In a recent stackoverflow question a user wanted this optional-subparsers ability in Python 2.7.

https://stackoverflow.com/questions/46667843/how-to-set-a-default-subparser-using-argparse-module-with-python-2-7

Short of modifying the _parse_known_args method, the best I could suggest was a two stage parsing.  That is, one parser without the subparsers.  This uses parse_known_args, and if a 'cmd' is provided passes the 'extras' to one that handles subparsers.

---

Another issue which I don't think has been addressed is the 'usage' when subparsers are optional.  At least with 3.5, subparsers are displayed with the choices: {'cmd1', 'cmd2', ...}, but no indication of being optional.  An optional positional (with ? nargs) would normally be displayed as

     prog [-h] [{'one', 'two'}] ...

My guess is that 'usage' adds the [] when positionals nargs='?', without regard to the 'required' attribute (I should verify this from code).

I'm undecided as to whether we want the brackets or not.  It's more accurate, but makes the usage messier.  And the 'help' grouping for 'optional-positionals' is the subject of other bug/issue(s).

I haven't checked it the patch has changed this behavior.
History
Date User Action Args
2017-10-18 18:58:42paul.j3setrecipients: + paul.j3, csernazs, bethard, jwilk, frispete, eric.araujo, r.david.murray, zzzeek, labrat, chris.jerdonek, nvie, DasIch, elsdoerfer, G2P, Julian, dsully, derks, seblu, bewest, bkabrda, couplewavylines, svilgelm, Anthony Sottile, Mariatta
2017-10-18 18:58:41paul.j3setmessageid: <1508353121.75.0.213398074469.issue9253@psf.upfronthosting.co.za>
2017-10-18 18:58:41paul.j3linkissue9253 messages
2017-10-18 18:58:41paul.j3create