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 Andrei.Vereha, Radu.Ciorba, Sam.Breese, bethard, idank, paul.j3, r.david.murray
Date 2013-04-17.22:38:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366238287.79.0.635450212886.issue16142@psf.upfronthosting.co.za>
In-reply-to
Content
parser = argparse.ArgumentParser()
    parser.add_argument('-k','--known',action='store_true')
    print(parser.parse_known_args(['-k','-u']))
    print(parser.parse_known_args(['-ku']))
    print(parser.parse_known_args(['-uk']))

I think you want these 3 cases to produce the same output:

    (Namespace(known=True), ['-u'])

With the attached patch, '-ku' produces the same result as '-k -u'. Instead of raising the "ignored explicit argument 'u'" error, if puts '-u' in the 'extras' list.  'parse_args' then raises a "error: unrecognized arguments: u" error.

That's an easy change, and does not break anything in the 'test_argparse.py' file.  But keep in mind that this test file mostly uses 'parse_args', and usually it ignores the failure messages.

Getting '-uk' to work this way would be much harder.  While it isn't obvious from the documentation, '-uk' is a valid option string, and '-u' is a valid abbreviation. Notice in 16.4.4.1. of the documentation, the difference between long and short options is based on the number of characters, not whether there it starts with '-' or '--'.  So identifying what is wrong with '-uk' would require ambiguous reasoning.

I wonder what optparse does.
History
Date User Action Args
2013-04-17 22:38:07paul.j3setrecipients: + paul.j3, bethard, r.david.murray, idank, Sam.Breese, Radu.Ciorba, Andrei.Vereha
2013-04-17 22:38:07paul.j3setmessageid: <1366238287.79.0.635450212886.issue16142@psf.upfronthosting.co.za>
2013-04-17 22:38:07paul.j3linkissue16142 messages
2013-04-17 22:38:07paul.j3create