Skip to content

[argparse] action='store_true' and action='store_false' are affected by argument_default #155403

Description

@jonathandung

Documentation

While the docs seem to imply that False and True are always the defaults for the store_true and store_false actions respectively, that is only true if argument_default is not passed. This should be more clearly documented.

>>> import argparse
>>> parser = argparse.ArgumentParser(prog='baz', argument_default=argparse.SUPPRESS)
>>> parser.add_argument('-s', '--spam', action='store_true')
_StoreTrueAction(option_strings=['-s', '--spam'], dest='spam', nargs=0, const=True, default='==SUPPRESS==', type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)
>>> parser.parse_args()
Namespace()
>>> parser.parse_args(['-s'])
Namespace(spam=True)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status
    No status
    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions