Message186110
There's another 'feature' to the patch proposed here. It only deletes the first '--' in the list of strings passed to '_get_values' for a particular action.
parser = argparse.ArgumentParser()
parser.add_argument('foo')
parser.add_argument('bar', nargs='*')
print(parser.parse_args('-- 1 -- 2 3 4'.split(' ')))
# Namespace(bar=['2', '3', '4'], foo='1')
'_get_values' first gets ('foo',['--','1']), then ('bar',['--','2','3','4'])
print(parser.parse_args('-- -- 1 -- 2 -- 3 4'.split(' ')))
# with this '1st only' change
# Namespace(bar=['1', '2', '--', '3', '4'], foo='--')
# without it, deleting all '--'; note foo is empty
# Namespace(bar=['1', '2', '3', '4'], foo=[])
And to confuse things a bit more:
print(parser.parse_args('1 -- 2 3 4'.split(' ')))
# Namespace(bar=['2', '3', '4'], foo='1')
passes ['1','--'] with 'foo'
If 'bar' nargs='...', bar gets all of the '--' (with or without this patch).
The handling of '--' is complex because it is used in one place to mean, 'everything else is an argument', effectively adding '-AA...' to the arg_strings_pattern. It also matches with the nargs_pattern (e.g. '(-*A-*)...'). And then it may or may not be removed in _get_values(). |
|
Date |
User |
Action |
Args |
2013-04-05 21:59:03 | paul.j3 | set | recipients:
+ paul.j3, bethard, eric.smith, kalt, r.david.murray, python-dev, wt, jeffknupp, gcbirzan |
2013-04-05 21:59:03 | paul.j3 | set | messageid: <1365199143.92.0.947817397442.issue13922@psf.upfronthosting.co.za> |
2013-04-05 21:59:03 | paul.j3 | link | issue13922 messages |
2013-04-05 21:59:03 | paul.j3 | create | |
|