Message187212
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. |
|
Date |
User |
Action |
Args |
2013-04-17 22:38:07 | paul.j3 | set | recipients:
+ paul.j3, bethard, r.david.murray, idank, Sam.Breese, Radu.Ciorba, Andrei.Vereha |
2013-04-17 22:38:07 | paul.j3 | set | messageid: <1366238287.79.0.635450212886.issue16142@psf.upfronthosting.co.za> |
2013-04-17 22:38:07 | paul.j3 | link | issue16142 messages |
2013-04-17 22:38:07 | paul.j3 | create | |
|