Skip to content

gh-155403: Document that store_true/store_false are affected by argument_default - #155404

Open
shoutoutuoadi325 wants to merge 1 commit into
python:mainfrom
shoutoutuoadi325:gh-155403-document-argparse-argument-default
Open

gh-155403: Document that store_true/store_false are affected by argument_default#155404
shoutoutuoadi325 wants to merge 1 commit into
python:mainfrom
shoutoutuoadi325:gh-155403-document-argparse-argument-default

Conversation

@shoutoutuoadi325

@shoutoutuoadi325 shoutoutuoadi325 commented Aug 9, 2026

Copy link
Copy Markdown

Issue

Issue #155403: The argparse documentation implies that store_true and store_false always have default values of False and True respectively, but this is only true when argument_default is not set. When argument_default=argparse.SUPPRESS is used, these defaults are also suppressed.

Reproduction

import argparse

# Without argument_default - defaults apply
parser1 = argparse.ArgumentParser()
parser1.add_argument('--spam', action='store_true')
print(parser1.parse_args([]))  # Namespace(spam=False)

# With argument_default=SUPPRESS - no attribute when flag not provided
parser2 = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
parser2.add_argument('--spam', action='store_true')
print(parser2.parse_args([]))  # Namespace() (no 'spam' attribute)

Fix

Updated the documentation to:

  1. Clarify that the defaults mentioned are affected by argument_default
  2. Added an example demonstrating the behavior with argument_default=SUPPRESS

Changes

  • Updated Doc/library/argparse.rst to document the interaction between store_true/store_false actions and argument_default
  • Added NEWS entry in Misc/NEWS.d/next/Documentation/

Testing

  • All argparse tests pass (1966 tests)
  • Verified documentation examples work correctly
  • make patchcheck passes

Copilot AI lite review requested due to automatic review settings August 9, 2026 04:38
@bedevere-app bedevere-app Bot added the docs Documentation in the Doc dir label Aug 9, 2026
@python-cla-bot

python-cla-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_false defaults are suppressed when argument_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.

Comment thread Doc/library/argparse.rst
Comment on lines +792 to +796
>>> 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)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Doc/library/argparse.rst
>>> 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33977875 | 📁 Comparing 3d42446 against main (998b890)

  🔍 Preview build  

2 files changed
± library/argparse.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants