Closed as not planned
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
Metadata
Metadata
Assignees
Projects
Status
Doc issues