This is an elaboration of issue #85039.
>>> parser = ArgumentParser()
>>> parser.add_argument('--foo', action=BooleanOptionalAction,
... choices=[1,2], metavar='FOOBAR', type=int) # doctest: +ELLIPSIS
BooleanOptionalAction(...)
Note that the store_const, store_true, and store_false actions disallow those keyword arguments.
>>> parser.add_argument('--bar', action="/deoxy?target=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2Fstore_true", choices=[1,2])
Traceback (most recent call last):
...
TypeError: __init__() got an unexpected keyword argument 'choices'
>>> parser.add_argument('--bar', action="/deoxy?target=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2Fstore_true", metavar='FOOBAR')
Traceback (most recent call last):
...
TypeError: __init__() got an unexpected keyword argument 'metavar'
>>> parser.add_argument('--bar', action="/deoxy?target=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2Fstore_true", type=int)
Traceback (most recent call last):
...
TypeError: __init__() got an unexpected keyword argument 'type'
>>> parser.add_argument('--bar', action="/deoxy?target=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2Fstore_true") # doctest: +ELLIPSIS
_StoreTrueAction(...)
Linked PRs