[New-bugs-announce] [issue22909] [argparse] Using parse_known_args, unknown arg with space in value is interpreted as first positional arg

Tab Atkins Jr. report at bugs.python.org
Thu Nov 20 22:28:58 CET 2014


New submission from Tab Atkins Jr.:

If using parse_known_args() to get argument pass-through, and one of the "unknown" arguments has a value with a space in it (even if quoted!), the entire unknown argument (key=value) will be interpreted as the value of the first positional argument instead.

Example:

```
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("pos", nargs="?", default=None)

parser.parse_known_args(["--foo='bar'"])
# (Namespace(pos=None), ['--foo=bar'])
# As expected.

parse.parse_known_args(["--foo='bar baz'"])
# (Namespace(pos="--foo='bar baz'"), [])
# What?!?
```

Since *known* arguments with spaces in them are parsed fine, this looks to be regression in a lesser-used feature.

----------
components: Library (Lib)
messages: 231448
nosy: TabAtkins
priority: normal
severity: normal
status: open
title: [argparse] Using parse_known_args, unknown arg with space in value is interpreted as first positional arg
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22909>
_______________________________________


More information about the New-bugs-announce mailing list