python / python/cpython

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

Open
#155,403 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-155404

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the argparse action documentation linked in the issue and compare its store_true/store_false wording with the argument_default example shown. Done means the documentation explicitly describes their interaction and preserves the demonstrated behavior; PR gh-155404 is already linked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.