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 paul.j3
Recipients conchylicultor, paul.j3, rhettinger, shihai1991, xtreak
Date 2020-12-11.19:59:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1607716747.24.0.647868367716.issue39106@roundup.psfhosted.org>
In-reply-to
Content
In the subparser example, it's the `build` subparser that puts '--overwritte' in the unrecognized list.  That is then passed back to the main parser, which then issues the 'unrecognized' error, along with its own usage.

The subparser is called with `parse_known_args` while the proposed patch is run in the `parse_args` method of the main parser.  It doesn't have access to the subparser's arguments.  So implementing the proposed matching will be much harder.

For some types of error, such as type or choices, the subparser itself raises the error, with the appropriate usage.  

===

https://bugs.python.org/issue42297
[argparse] Bad error message formatting when using custom usage text

is another case where error messages produced by the subparser differ from messages produced by the main. In this case the unrecognized error usage message is clearer since it is produced by the main parser.

===

I didn't close this issue, but it does feel like an enhancement that's too big for the bug/issues forum.  The proposed patch could be developed as a separate 'parser.parse_args_with_hints' method, and distributed as a pypi addition.  During development and testing, the regular 'parser.parse_args()' does not need to be touched.
History
Date User Action Args
2020-12-11 19:59:07paul.j3setrecipients: + paul.j3, rhettinger, xtreak, shihai1991, conchylicultor
2020-12-11 19:59:07paul.j3setmessageid: <1607716747.24.0.647868367716.issue39106@roundup.psfhosted.org>
2020-12-11 19:59:07paul.j3linkissue39106 messages
2020-12-11 19:59:07paul.j3create