[issue41600] Expected behavior of argparse given quoted strings

Vegard Stikbakke report at bugs.python.org
Thu Aug 20 08:00:44 EDT 2020


Vegard Stikbakke <vegard.stikbakke at gmail.com> added the comment:

In fact, what happens in the latter case (i.e. `"--a 1 --b 2"`), inside the call to `_parse_optional`, is that it fails to get the optional tuple. And so it continues to this line in argparse.py: 
https://github.com/python/cpython/blob/2ce39631f679e14132a54dc90ce764259d26e166/Lib/argparse.py#L2227

Here it says that if there's a space in the string, it was meant to be a positional, and so the function returns `None`, causing it to not find the argument.

In conclusion, it seems to me that argparse is not, in fact, meant to handle quoted strings, or rather, strings where there are spaces.

----------

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


More information about the Python-bugs-list mailing list