-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
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-featureA feature request or enhancementA feature request or enhancement
Description
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
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Doc issues