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']) ``` <!-- gh-linked-prs --> ### Linked PRs * gh-124145 * gh-124233 * gh-124274 * gh-124276 * gh-125068 <!-- /gh-linked-prs -->
Activity
pythongh-95468: fix doubledash skip in argparse
pythongh-95468: add more narg options
Merge branch 'main' into pythongh-95468
pythongh-95468: Fix handling of multiple "--" (double dashes) in argp…
serhiy-storchaka commentedon Sep 19, 2024
This is a duplicate of #81691.
pythongh-95468: Add more tests for "--" (double dash) in test_argparse
gh-95468: Add more tests for "--" (double dash) in test_argparse (GH-…
pythongh-95468: Add more tests for "--" (double dash) in test_argparse (
[3.12] gh-95468: Add more tests for "--" (double dash) in test_argpar…
pythongh-95468: Add more tests for "--" (double dash) in test_argparse (
pythongh-95468: Add more tests for "--" (double dash) in test_argparse (
pythongh-95468: Add more tests for "--" (double dash) in test_argparse (
[3.13] gh-95468: Add more tests for "--" (double dash) in test_argpar…