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 martin.panter
Recipients bethard, eric.araujo, maker, martin.panter, paul.j3, r.david.murray
Date 2016-03-28.01:49:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459129772.52.0.352628151213.issue14364@psf.upfronthosting.co.za>
In-reply-to
Content
In Python 3.5, this does not seem fixed. Issue 13922 is marked as resolved and fixed, but Pauls’s patch has not actually been committed.

>>> ap = ArgumentParser()
>>> ap.add_argument("-t", "--test", type=str, nargs=1)
_StoreAction(option_strings=['-t', '--test'], dest='test', nargs=1, const=None, default=None, type=<class 'str'>, choices=None, help=None, metavar=None)
>>> ap.add_argument('yuri', nargs='?')
_StoreAction(option_strings=[], dest='yuri', nargs='?', const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> ap.parse_args(["--test=--", "foo"])
Namespace(test=[], yuri='foo')
>>> ap.parse_args(["--test", "--", "foo"])
usage: [-h] [-t TEST] [yuri]
: error: argument -t/--test: expected 1 argument
argparse.ArgumentError: argument -t/--test: expected 1 argument

During handling of the above exception, another exception occurred:

__main__.SystemExit: 2
>>> ap.parse_args(["-t--", "foo"])
Namespace(test=[], yuri='foo')
>>> ap.parse_args(["-t", "--", "foo"])
usage: [-h] [-t TEST] [yuri]
: error: argument -t/--test: expected 1 argument
argparse.ArgumentError: argument -t/--test: expected 1 argument

During handling of the above exception, another exception occurred:

__main__.SystemExit: 2
History
Date User Action Args
2016-03-28 01:49:32martin.pantersetrecipients: + martin.panter, bethard, eric.araujo, r.david.murray, maker, paul.j3
2016-03-28 01:49:32martin.pantersetmessageid: <1459129772.52.0.352628151213.issue14364@psf.upfronthosting.co.za>
2016-03-28 01:49:32martin.panterlinkissue14364 messages
2016-03-28 01:49:31martin.pantercreate