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 paul.j3, siming85
Date 2018-08-28.22:19:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1535494771.51.0.56676864532.issue34479@psf.upfronthosting.co.za>
In-reply-to
Content
Errors that are associated with a specific argument, such as a wrong 'type' do get usage from the appropriate subparser.  

e.g.

In [164]: p.parse_args('--foo 1 cmd1 --bar x'.split())
usage: ipython3 cmd1 [-h] [--bar BAR]
ipython3 cmd1: error: argument --bar: invalid int value: 'x'

`required` tests also issue subparser specific usage; mutually exclusive tests probably do so as well.

But this unrecognized argument error is a bit less specific.  In your example '-x a' and 'a -x' will both produce the same error message.  The route by which the '-x' is put into the 'extras' list is different in the two cases, but in both it's the top 'parse_(known_)args' that determines whether to just return them, or raise an error.  '-x a -x' will put 2 '-x' in the unrecognized list.

If you really need a subparser specific message it might be possible to do so by modifying, or subclassing the _SubParsersAction class, making it raise an error when there are 'extras' rather than returning them as 'unrecognized'.  But that's not a backward compatible change.
History
Date User Action Args
2018-08-28 22:19:31paul.j3setrecipients: + paul.j3, siming85
2018-08-28 22:19:31paul.j3setmessageid: <1535494771.51.0.56676864532.issue34479@psf.upfronthosting.co.za>
2018-08-28 22:19:31paul.j3linkissue34479 messages
2018-08-28 22:19:31paul.j3create