Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@Nikratio

Description

@Nikratio
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
No fields configured for issues without a type.

Projects

Status
Doc issues
Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.