Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse not including '--' arguments in previous optional REMAINDER argument #66419

Open
JurkoGospodneti mannequin opened this issue Aug 18, 2014 · 2 comments
Open

argparse not including '--' arguments in previous optional REMAINDER argument #66419

JurkoGospodneti mannequin opened this issue Aug 18, 2014 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JurkoGospodneti
Copy link
Mannequin

JurkoGospodneti mannequin commented Aug 18, 2014

BPO 22223

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2014-08-18.09:46:02.121>
labels = ['type-bug', 'library']
title = "argparse not including '--' arguments in previous optional REMAINDER argument"
updated_at = <Date 2014-08-20.13:47:19.982>
user = 'https://bugs.python.org/JurkoGospodneti'

bugs.python.org fields:

activity = <Date 2014-08-20.13:47:19.982>
actor = 'Juraj.Ivancic'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2014-08-18.09:46:02.121>
creator = 'Jurko.Gospodneti\xc4\x87'
dependencies = []
files = []
hgrepos = []
issue_num = 22223
keywords = []
message_count = 2.0
messages = ['225484', '225485']
nosy_count = 2.0
nosy_names = ['Jurko.Gospodneti\xc4\x87', 'Juraj.Ivancic']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue22223'
versions = ['Python 2.7', 'Python 3.4']

@JurkoGospodneti
Copy link
Mannequin Author

JurkoGospodneti mannequin commented Aug 18, 2014

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ć

@JurkoGospodneti JurkoGospodneti mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 18, 2014
@JurkoGospodneti
Copy link
Mannequin Author

JurkoGospodneti mannequin commented Aug 18, 2014

Might be related to the following issues:

http://bugs.python.org/issue9571
http://bugs.python.org/issue13922

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: Bugs
Development

No branches or pull requests

0 participants