Message188743
Wouldn't it be simpler to use the re {m,n} notation to grab the appropriate number of arguments?
In ArgumentParser _get_nargs_pattern we could add:
+ # n to m arguments, nargs is re like {n,m}
+ elif is_mnrep(nargs):
+ nargs_pattern = '([-A]%s)'%nargs
# all others should be integers
where is_mnrep() tests that the nargs string looks like '{m,n}' (or '{,n}' or '{m,}'). The resulting nargs_pattern will look like
'([-A]{m,n})'
In _format_args() a similar addition would be:
+ elif is_mnrep(action.nargs):
+ result = '%s%s' % (get_metavar(1)[0], action.nargs)
'FOO{2,5}'
It would take more code to generate
FOO FOO [FOO [FOO [FOO]]]
A matching programmer input would be:
parser.add_argument('Foo', nargs='{2,5}')
though it wouldn't be much work to also translate a tuple.
parser.add_argument('Foo', nargs=(2,5))
I'll try to test this implementation against wm's tests. |
|
Date |
User |
Action |
Args |
2013-05-08 22:32:57 | paul.j3 | set | recipients:
+ paul.j3, bethard, Danh, wm, atfrase |
2013-05-08 22:32:57 | paul.j3 | set | messageid: <1368052377.47.0.750391302772.issue11354@psf.upfronthosting.co.za> |
2013-05-08 22:32:57 | paul.j3 | link | issue11354 messages |
2013-05-08 22:32:57 | paul.j3 | create | |
|