Skip to content

gh-127296: Document that argparse count action starts from a non-zero default - #156908

Open
owenthcarey wants to merge 1 commit into
python:mainfrom
owenthcarey:gh-127296-argparse-count-default
Open

gh-127296: Document that argparse count action starts from a non-zero default#156908
owenthcarey wants to merge 1 commit into
python:mainfrom
owenthcarey:gh-127296-argparse-count-default

Conversation

@owenthcarey

@owenthcarey owenthcarey commented Sep 3, 2026

Copy link
Copy Markdown

The 'count' action adds to whatever value is already in the namespace, so with default=3 a single -v gives 4, not 1. The docs don't say this, and the general description of default reads as if the default is only used when the argument is absent.

This adds one sentence to the 'count' entry saying that a non-zero default is the starting point for the count, as suggested in the issue.

Fixes #127296

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34380293 | 📁 Comparing 8da8655 against main (c8ea867)

  🔍 Preview build  

1 file changed
± library/argparse.html

Comment thread Doc/library/argparse.rst
Comment on lines 838 to +840
Note, the *default* will be ``None`` unless explicitly set to *0*.
If the default value is a non-zero number, the count starts from that
number rather than from zero.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Note, the *default* will be ``None`` unless explicitly set to *0*.
If the default value is a non-zero number, the count starts from that
number rather than from zero.
Unless explicitly set, the *default* will be ``None``. If the default
value is a non-zero number, the count starts from that number rather
than from zero.

Minor tweak because I think the preceding sentence could also be worded better.

@savannahostrowski savannahostrowski added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 4, 2026
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 needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Argparse: "default" interacts incorrectly/non-intuitively with action="count"

2 participants