Bug report
Bug description:
Consider the following cut-down script:
import argparse
import pprint
ap = argparse.ArgumentParser()
ap.add_argument("p", nargs="?")
ap.add_argument("q", nargs="?")
ap.add_argument("--test", action="store_true")
args = ap.parse_args()
pprint.pprint(args.__dict__)
When invoked with two positional arguments and --test on either side of them, the behavior is as expected:
$ python3 test.py --test a b
{'p': 'a', 'q': 'b', 'test': True}
$ python3 test.py a b --test
{'p': 'a', 'q': 'b', 'test': True}
However, if you put --test in between the two positionals, argparse misinterprets the argument list:
$ python3 test.py a --test b
usage: test.py [-h] [--test] [p] [q]
test.py: error: unrecognized arguments: b
This argument list should produce the same Namespace object as the first two examples.
CPython versions tested on:
3.9, 3.11, 3.12
Operating systems tested on:
Linux
Bug report
Bug description:
Consider the following cut-down script:
When invoked with two positional arguments and
--teston either side of them, the behavior is as expected:However, if you put
--testin between the two positionals, argparse misinterprets the argument list:This argument list should produce the same Namespace object as the first two examples.
CPython versions tested on:
3.9, 3.11, 3.12
Operating systems tested on:
Linux