Bug report
When store_true, store_false, or store_const is set as an action of positional argument, the behaviour is counterintuitive. Running this small program:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('pos', action='store_true')
print(parser.parse_args([]))
outputs Namespace(pos=True). Changing last line to print(parser.parse_args(['foo'])) gives an error:
usage: prog.py [-h]
prog.py: error: unrecognized arguments: foo
Your environment
- CPython versions tested on: 3.10.2
- Operating system and architecture: Linux x86-64
Expected behaviour
I believe there is no good reason to allow setting those actions to positional arguments. Trying to do so should result in raising an exception (as is the case when trying to set required).
Linked PRs
Bug report
When
store_true,store_false, orstore_constis set as anactionof positional argument, the behaviour is counterintuitive. Running this small program:outputs
Namespace(pos=True). Changing last line toprint(parser.parse_args(['foo']))gives an error:Your environment
Expected behaviour
I believe there is no good reason to allow setting those actions to positional arguments. Trying to do so should result in raising an exception (as is the case when trying to set
required).Linked PRs