This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Anthony Sottile
Recipients Anthony Sottile, bethard, eric.araujo, memeplex, paul.j3, wolma
Date 2018-03-20.15:38:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521560282.75.0.467229070634.issue33109@psf.upfronthosting.co.za>
In-reply-to
Content
The intention of the change in issue 26510 was to pick the least surprising behaviour for the default value of subparsers -- the compatiblity with the behaviour before the regression was introduced in 3.3 was a nice side-effect.  As with the rest of positional arguments in argparse, the positional subparsers were changed to required by default.

The main issue addressing the 3.3 regression I believe is https://bugs.python.org/issue9253 and not the one linked.

When I revived the patch, I surveyed a number of open source tools using subparsers (~10-20) and they all fell into the following categories:

- Used the workaround (part of this SO post: https://stackoverflow.com/a/23354355/812183) (most fell into this category)
- crashed with some sort of TypeError (NoneType has no attribute startswith, KeyeError: None, etc.) due to not handling "optional" subparsers
- Manually handled when the subparser was `None` to raise an argparse error

You can enable a 3.3-3.7 compatible "always optional subparsers" with a similar pattern that was used to manually restore the pre-regression behaviour:

subparsers = parser.add_subparsers(...)
subparsers.required = False

I believe the error message issue is already tracked: https://bugs.python.org/issue29298
History
Date User Action Args
2018-03-20 15:38:02Anthony Sottilesetrecipients: + Anthony Sottile, bethard, eric.araujo, memeplex, paul.j3, wolma
2018-03-20 15:38:02Anthony Sottilesetmessageid: <1521560282.75.0.467229070634.issue33109@psf.upfronthosting.co.za>
2018-03-20 15:38:02Anthony Sottilelinkissue33109 messages
2018-03-20 15:38:02Anthony Sottilecreate