Skip to content

Minor documentation fix: incorrect statement about argparse.ArgumentParser.add_argument()#145479

Merged
savannahostrowski merged 4 commits intopython:mainfrom
jkunimune:patch-3
Mar 3, 2026
Merged

Minor documentation fix: incorrect statement about argparse.ArgumentParser.add_argument()#145479
savannahostrowski merged 4 commits intopython:mainfrom
jkunimune:patch-3

Conversation

@jkunimune
Copy link
Contributor

@jkunimune jkunimune commented Mar 3, 2026

The documentation for the name or flags argument of argparse.ArgumentParser.add_argument() said

The dest parametre defaults to the argument name with underscores _ replacing hyphens - .

However, this is not true for positional arguments, which retain their hyphens. The documentation for the dest parameter correctly describes this behavior, but a user who only reads the name or flags documentation will be misled.

Thus, I added a qualification to the sentence to make clear that the hyphen relpacement only happens for optional arguments.

The dest parameter defaults to the argument name, with underscores _ replacing hyphens - if the argument is optional.

I'm hoping this change is trivial enough that I don't need to submit an issue first, but let me know if that's incorrect.


📚 Documentation preview 📚: https://cpython-previews--145479.org.readthedocs.build/

The documentation for the name or flags argument of `argparse.ArgumentParser.add_argument()` said

> By default, argparse automatically handles the internal naming and display names of arguments … The dest parametre defaults to the argument name with underscores `_` replacing hyphens `-` .

However, this is not true for positional arguments, which retain their hyphens.  The documentation for the dest parameter correctly describes this behavior, but a user who only reads the name or flags documentation will be misled.

Thus, I added a qualification to the sentence to make clear that the hyphen relpacement only happens for optional argiments.
Copy link
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

Good catch - just a tweak on the phrasing but LGTM! Thank you!

@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Co-authored-by: Savannah Ostrowski <savannah@python.org>
@jkunimune
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2026

Thanks for making the requested changes!

@savannahostrowski: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from savannahostrowski March 3, 2026 21:12
Copy link
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

One small comment but after that's fixed, I'll merge and backport.

@jkunimune
Copy link
Contributor Author

Ah, good point. I just fixed it.

@savannahostrowski savannahostrowski enabled auto-merge (squash) March 3, 2026 21:35
@savannahostrowski savannahostrowski merged commit dc12d19 into python:main Mar 3, 2026
28 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Mar 3, 2026
@miss-islington-app
Copy link

Thanks @jkunimune for the PR, and @savannahostrowski for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @jkunimune and @savannahostrowski, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker dc12d1999b88e84d5a6b8e491be468b73379e54b 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 3, 2026
…ythonGH-145479)

(cherry picked from commit dc12d1999b88e84d5a6b8e491be468b73379e54b)

Co-authored-by: Justin Kunimune <justinkunimune@gmail.com>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2026

GH-145485 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 3, 2026
@savannahostrowski savannahostrowski removed the needs backport to 3.13 bugs and security fixes label Mar 3, 2026
@savannahostrowski
Copy link
Member

These docs were added in 3.14 so removing backport to 3.13 label.

savannahostrowski added a commit that referenced this pull request Mar 3, 2026
…ment() (GH-145479) (#145485)

Fix incorrect statement about argparse.ArgumentParser.add_argument() (GH-145479)
(cherry picked from commit dc12d19)

Co-authored-by: Justin Kunimune <justinkunimune@gmail.com>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
bkap123 pushed a commit to bkap123/cpython that referenced this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants