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 <>
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 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: (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:
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: <>
2018-03-20 15:38:02Anthony Sottilelinkissue33109 messages
2018-03-20 15:38:02Anthony Sottilecreate