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.

classification
Title: argparse not including '--' arguments in previous optional REMAINDER argument
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Juraj.Ivancic, Jurko.Gospodnetić
Priority: normal Keywords:

Created on 2014-08-18 09:46 by Jurko.Gospodnetić, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg225484 - (view) Author: Jurko Gospodnetić (Jurko.Gospodnetić) * Date: 2014-08-18 09:46
If you have an optional nargs=argparse.REMAINDER argument defined
then, if specified, its value should contain all the remaining command-line content. However, it seems that value does not include later '--' arguments.

For example, the following works as expected:

import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("--args", nargs=argparse.REMAINDER)
args = parser.parse_args("--args cmd --arg1 XX ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "ZZ"]

But the following fails with
'PROG: error: unrecognized arguments: -- ZZ':

import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("--args", nargs=argparse.REMAINDER)
args = parser.parse_args("--args cmd --arg1 XX -- ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"]


Note that the same code works as expected when using a
positional nargs=argparse.REMAINDER arguments:

import argparse
parser = argparse.ArgumentParser(prog="PROG")
parser.add_argument("args", nargs=argparse.REMAINDER)
args = parser.parse_args("args cmd --arg1 XX ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "ZZ"]
args = parser.parse_args("args cmd --arg1 XX -- ZZ".split())
assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"]

But that, of course, does not allow us to have the args value
start with something like "--blah" that looks like an optional
argument.


Hope this helps.

Best regards,
  Jurko Gospodnetić
msg225485 - (view) Author: Jurko Gospodnetić (Jurko.Gospodnetić) * Date: 2014-08-18 09:46
Might be related to the following issues:

http://bugs.python.org/issue9571
http://bugs.python.org/issue13922
History
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66419
2014-08-20 13:47:19Juraj.Ivancicsetnosy: + Juraj.Ivancic
2014-08-18 09:46:19Jurko.Gospodnetićsetmessages: + msg225485
2014-08-18 09:46:02Jurko.Gospodnetićcreate