-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-87358: Add clarification about nargs and default argparse behaviour #124094
Conversation
Doc/library/argparse.rst
Outdated
For other nargs_ values, the argument is treated as a required argument and | ||
the default_ value is ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks misleading, because it is not clear that this only relates to positional arguments.
On other hand, default is also has no effect for required optional arguments.
We could say that the default value is ignored for required arguments (there may be a reference to the required
attribute).
For future reference: Avoid rebase and force pushing as it causes codeowners assignment for all of the other changes rebased in. Just merge main in instead. We all do this from time to time. (Even at work!) It's a GitHub git internals UX flaw. 😅 |
Yeah, oof, that's my bad! Apologies for the noise, folks 😅. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about wording. LGTM, but it would be better if some of native speakers check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wording is good, thanks!
@@ -1122,6 +1122,9 @@ is used when no command-line argument was present:: | |||
>>> parser.parse_args([]) | |||
Namespace(foo=42) | |||
|
|||
For required_ arguments, the ``default`` value is ignored. For example, this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: we have a (somewhat unusual) convention of using italics for arguments instead of literal code formatting:
https://devguide.python.org/documentation/markup/
But I see we're using literals elsewhere in this file so it's best to be consistent.
Thanks @savannahostrowski for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…haviour (pythonGH-124094) (cherry picked from commit 20ccda0) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
GH-124440 is a backport of this pull request to the 3.13 branch. |
…haviour (pythonGH-124094) (cherry picked from commit 20ccda0) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
GH-124441 is a backport of this pull request to the 3.12 branch. |
After reading through the issue's comments, it seems like all that's needed here is additional clarification in the argparse docs about how
nargs
anddefault
interact.📚 Documentation preview 📚: https://cpython-previews--124094.org.readthedocs.build/