-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed as not planned
Closed as not planned
Copy link
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
Description
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
- GH-95468: Prevent argparse from removing
--in cases where used to delineate positional args #124145 - gh-81691: Fix handling of multiple "--" (double dashes) in argparse #124233
- gh-95468: Add more tests for "--" (double dash) in test_argparse #124274
- [3.12] gh-95468: Add more tests for "--" (double dash) in test_argparse (GH-124274) #124276
- [3.13] gh-95468: Add more tests for "--" (double dash) in test_argparse (GH-124274) #125068
vergenzt, falkben, silverwind, cdevoogd, dcolascione and 1 more
Metadata
Metadata
Assignees
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
Projects
Status
Doc issues