gh-155403: Document that store_true/store_false are affected by argument_default - #155404
Conversation
… argument_default
There was a problem hiding this comment.
Pull request overview
Updates the argparse documentation to clarify that the implicit defaults for action='store_true' / action='store_false' depend on the parser-wide argument_default setting (notably SUPPRESS), aligning the docs with actual behavior.
Changes:
- Document that
store_true/store_falsedefaults are suppressed whenargument_default=SUPPRESS. - Add an example demonstrating the suppressed-default behavior.
- Add a documentation NEWS fragment for the change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Doc/library/argparse.rst | Clarifies and demonstrates how argument_default=SUPPRESS affects store_true/store_false defaults. |
| Misc/NEWS.d/next/Documentation/2026-08-09-12-00-00.gh-issue-155403.wX8kR2.rst | Adds a NEWS entry describing the documentation update. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) | ||
| >>> parser.add_argument('--foo', action='store_true') | ||
| >>> parser.add_argument('--bar', action='store_false') | ||
| >>> parser.parse_args('--foo'.split()) | ||
| Namespace(foo=True) # bar and baz are suppressed (not present) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d4244626e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| >>> parser.add_argument('--foo', action='store_true') | ||
| >>> parser.add_argument('--bar', action='store_false') | ||
| >>> parser.parse_args('--foo'.split()) | ||
| Namespace(foo=True) # bar and baz are suppressed (not present) |
There was a problem hiding this comment.
Mention only arguments registered on the second parser
The second example replaces parser and registers only foo and bar, so baz is not suppressed—it does not exist on this parser at all. This makes the new explanation factually misleading; either register baz again or state only that bar is suppressed.
Useful? React with 👍 / 👎.
Documentation build overview
|
Issue
Issue #155403: The argparse documentation implies that
store_trueandstore_falsealways have default values ofFalseandTruerespectively, but this is only true whenargument_defaultis not set. Whenargument_default=argparse.SUPPRESSis used, these defaults are also suppressed.Reproduction
Fix
Updated the documentation to:
argument_defaultargument_default=SUPPRESSChanges
Doc/library/argparse.rstto document the interaction betweenstore_true/store_falseactions andargument_defaultMisc/NEWS.d/next/Documentation/Testing
make patchcheckpassesargparse]action='store_true'andaction='store_false'are affected byargument_default#155403