Skip to content

argparse.BooleanOptionalAction accepts and silently discards choices, metavar, and type arguments #92248

Description

@samwyse

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='store_true', choices=[1,2])
Traceback (most recent call last):
  ...
TypeError: __init__() got an unexpected keyword argument 'choices'
>>> parser.add_argument('--bar', action='store_true', metavar='FOOBAR')
Traceback (most recent call last):
  ...
TypeError: __init__() got an unexpected keyword argument 'metavar'
>>> parser.add_argument('--bar', action='store_true', type=int)
Traceback (most recent call last):
  ...
TypeError: __init__() got an unexpected keyword argument 'type'
>>> parser.add_argument('--bar', action='store_true')  # doctest: +ELLIPSIS
_StoreTrueAction(...)

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on May 3, 2022
  2. self-assigned this
    on Apr 22, 2023
  3. added a commit that references this issue on Apr 22, 2023
  4. added a commit that references this issue on May 19, 2023
  5. added a commit that references this issue on May 20, 2023
  6. moved this from Bugs to Doc issues in Argparse issueson May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions