[New-bugs-announce] [issue35049] argparse.ArgumentParser fails on arguments with leading dash and comma

Lene Preuss report at bugs.python.org
Tue Oct 23 06:26:52 EDT 2018


New submission from Lene Preuss <lene.preuss at gmail.com>:

Obligatory apologies if this has been reported before, I could not find it. It is similar to but different from https://bugs.python.org/issue9334.

>>> from argparse import ArgumentParser
>>> p = ArgumentParser()
>>> p.add_argument('-d')
_StoreAction(option_strings=['-d'], dest='d', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> p.parse_args(['-d', '12'])
Namespace(d='12')
>>> p.parse_args(['-d', '1,2'])
Namespace(d='1,2')
>>> p.parse_args(['-d', '-12'])
Namespace(d='-12')
>>> p.parse_args(['-d', '-1,2'])
usage: [-h] [-d D]
: error: argument -d: expected one argument

As suggested in issue 9334, passing the argument with an equals sign works:
>>> p.parse_args(['-d=-1,2'])
Namespace(d='-1,2')

But I don't think that this is the intended behavior.

----------
messages: 328299
nosy: lene
priority: normal
severity: normal
status: open
title: argparse.ArgumentParser fails on arguments with leading dash and comma
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35049>
_______________________________________


More information about the New-bugs-announce mailing list