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.ArgumentParser silently swallows multiple -- (double dash) #95468

Closed
Nikratio opened this issue Jul 30, 2022 · 1 comment
Closed

argparse.ArgumentParser silently swallows multiple -- (double dash) #95468

Nikratio opened this issue Jul 30, 2022 · 1 comment
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Nikratio
Copy link

Nikratio commented Jul 30, 2022

Consider this:

import argparse
p = argparse.ArgumentParser()
p.add_argument('arg1', type=str)
p.add_argument('args', nargs='*')
p.parse_args(['foo', '--', '--bar', '--', 'com'])

The semantics of -- are to not attempt to parse the remaining command line options as parameters. Therefore, the expected output is:

Namespace(arg1='foo', args=['--bar', '--', 'com'])

However, the actual output is:

Namespace(arg1='foo', args=['--bar', 'com'])

In other words, the second -- has silently been dropped.

Interestingly enough, if the arg1 parameter is dropped, this works correctly:

p = argparse.ArgumentParser()
p.add_argument('args', nargs='*')
p.parse_args(['foo', '--', '--bar', '--', 'com'])
--> Namespace(args=['foo', '--bar', '--', 'com'])

Linked PRs

@Nikratio Nikratio added the type-bug An unexpected behavior, bug, or error label Jul 30, 2022
@AlexWaygood AlexWaygood added the stdlib Python modules in the Lib dir label Jul 30, 2022
PurityLake added a commit to PurityLake/cpython that referenced this issue Jul 31, 2022
PurityLake added a commit to PurityLake/cpython that referenced this issue Jul 31, 2022
savannahostrowski added a commit to savannahostrowski/cpython that referenced this issue Sep 16, 2024
@serhiy-storchaka serhiy-storchaka self-assigned this Sep 18, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 19, 2024
…arse

Only the first one has now been removed, all subsequent ones are now
taken literally.
@serhiy-storchaka
Copy link
Member

This is a duplicate of #81691.

@serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 20, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 20, 2024
pythonGH-124274)

(cherry picked from commit baa3550)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Sep 22, 2024
…se (GH-124274) (GH-124276)

(cherry picked from commit baa3550)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 7, 2024
pythonGH-124274)

(cherry picked from commit baa3550)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Oct 7, 2024
…se (GH-124274) (GH-125068)

(cherry picked from commit baa3550)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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: Doc issues
Development

Successfully merging a pull request may close this issue.

3 participants