paul j3 added the comment: 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. ---------- nosy: +paul.j3 Added file: http://bugs.python.org/file30181/prelimary.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11354> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com