Skip to content

Conversation

PrinceNaroliya
Copy link
Contributor

@PrinceNaroliya PrinceNaroliya commented Sep 1, 2025

What does this PR do?

This PR fixes a documentation issue in the argparse module related to the add_argument() method when using nargs='?'.

Previously, the docs stated:

"if the option string is encountered with no command-line argument following it, the value of `const` will be assumed to be `None` instead."

This is incorrect. The correct behavior is:

"if the option string is encountered with no command-line argument following it, the value from `const` will be used."

This PR updates the documentation to reflect the correct behavior.


Related Issue

Fixes: #137988


Type of Change

  • Documentation (typo, clarification, or instruction update)

How to Verify

  1. Open Doc/library/argparse.rst.

  2. Locate the passage describing nargs='?' and const.

  3. Confirm the updated sentence is:

    "the value from const will be used."

  4. Build HTML docs (optional) to verify changes:

    cd Doc
    .\make html
    start _build/html/library/argparse.html

Checklist

  • My change is a documentation fix.
  • I have tested the change locally (HTML build).
  • I have linked the related issue.

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

@bedevere-app bedevere-app bot added awaiting review docs Documentation in the Doc dir skip news labels Sep 1, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Sep 1, 2025
@PrinceNaroliya PrinceNaroliya changed the title Fix const description in add_argument() docs Fix const description in argparse.add_argument() docs (#137988) Sep 1, 2025
@PrinceNaroliya PrinceNaroliya changed the title Fix const description in argparse.add_argument() docs (#137988) gh-137988: Fix const description in argparse.add_argument() docs (#137988) Sep 3, 2025
@PrinceNaroliya
Copy link
Contributor Author

Hi, just checking in on this PR — would really appreciate it if you could take a look whenever you get a chance. Thanks!

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.

Thank you for the PR! LGTM!

@savannahostrowski savannahostrowski added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Sep 17, 2025
@savannahostrowski savannahostrowski changed the title gh-137988: Fix const description in argparse.add_argument() docs (#137988) gh-137988: Fix const description in argparse.add_argument() docs Sep 17, 2025
@savannahostrowski savannahostrowski enabled auto-merge (squash) September 17, 2025 15:10
@savannahostrowski savannahostrowski merged commit 37425fe into python:main Sep 17, 2025
27 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Sep 17, 2025
@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2025
pythonGH-138315)

(cherry picked from commit 37425fe)

Co-authored-by: PrinceNaroliya <[email protected]>
Co-authored-by: Savannah Bailey <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2025
pythonGH-138315)

(cherry picked from commit 37425fe)

Co-authored-by: PrinceNaroliya <[email protected]>
Co-authored-by: Savannah Bailey <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 17, 2025

GH-139051 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 Sep 17, 2025
@bedevere-app
Copy link

bedevere-app bot commented Sep 17, 2025

GH-139052 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 17, 2025
hugovk pushed a commit that referenced this pull request Sep 17, 2025
savannahostrowski added a commit that referenced this pull request Sep 17, 2025
@PrinceNaroliya PrinceNaroliya deleted the fix-argparse-const-doc branch September 18, 2025 08:13
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 news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

argparse: add_argument(): error about "const" argument
2 participants