-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-130750: Fix invalid choices documentation #130751
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
Open
TheDSCPL
wants to merge
1
commit into
python:main
Choose a base branch
from
TheDSCPL:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sorry, can you please calrify why do you want to change this?
Right now this reads perfectly fine to me:
'sum'and'max'are strings, defined aschoices=['sum', 'max']Uh oh!
There was an error while loading. Please reload this page.
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 think we have a small discrepency here:
cpython/Lib/argparse.py
Lines 2584 to 2587 in c9932a9
Technically, we shouldn't have quotes because we do
map(str, ...)and notmap(repr, ...). However!!! on 3.12.6 (not latest one):Whereas on main or latest 3.12:
We have indeed a discrepency. We actually changed this in 21524ee, so it was an omission during the backport. But I'm not sure whether
stris actually better.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.
Oh, interesting. Tbh, I prefer the readability of the explicit string, even though it's obvious in the example in question. It reads strangely to me that we'd have the invalid choice with quotes and then the supported choices without quotes. Consistency is good :)
Uh oh!
There was an error while loading. Please reload this page.
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 think the issue with the docs is that we're using 1-char choices which make the output slightly disturbing. I would suggest using words such as foo and bar to make it more readable.
However, I personally find it better to use repr() because it also highlights what's being expected. It's quite common to have error messages that contain the repr of the invalid argument instead of its str() so I wouldn't change that part.
Thus, my personal choice would be to use the repr() for the choices as well, though for enumeration choices, I don't know how it renders (for enum members the str() is usually better I think?)
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 don't have any preference for this. I was building a package from source that depended on cpython and had a test failing due to the expected stderr being different than the actual output because of the quotation marks. Upon looking into your code and documentation, I noticed the discrepancy and decided to create this PR to make the docs match the actual output. If you'd prefer to go back to the quoted version, then please close this PR and change the code to include the quotes again. Changing the output is a breaking change because tests that are expected to fail usually rely on the error message.
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.
Also, as I mentioned in the issue for this PR, even though argparse doesn't quote anymore, optparse still does, so it's inconsistent.