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 Danh, atfrase, bethard, paul.j3, wm
Date 2013-05-08.22:32:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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


In _format_args() a similar addition would be:

+        elif is_mnrep(action.nargs):
+            result = '%s%s' % (get_metavar(1)[0], action.nargs)


It would take more code to generate


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:57paul.j3setrecipients: + paul.j3, bethard, Danh, wm, atfrase
2013-05-08 22:32:57paul.j3setmessageid: <>
2013-05-08 22:32:57paul.j3linkissue11354 messages
2013-05-08 22:32:57paul.j3create