Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-86357: argparse: use str() consistently and explicitly to print choices#117766
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
rindeal commented Apr 11, 2024 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
ghost commented Apr 11, 2024 • edited by ghost
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by ghost
Uh oh!
There was an error while loading. Please reload this page.
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
JelleZijlstra commented Apr 19, 2024
Since this changes user-facing behavior, it needs an issue and a NEWS entry. The change in |
rindeal commented Apr 19, 2024
Done
True. But that's a job for |
encukou commented May 6, 2024
Since this changes user-facing behavior, it needs an issue. Do you want to file one? As the docs say:
So, in today's As far as I know, |
rindeal commented May 9, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Done. #118839
That concerns #86667, which is unrelated to this one. The fix for the issue then, in fact, introduced another bug, ie., the sentence you quoted. It just comments on the bad code example the fix deleted and does not hold up on its own, since anything can be used as choices and one can always expect to see
Using |
nineteendo commented May 9, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Could you add gh-118839 to the title? |
serhiy-storchaka left a comment
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.
Please add tests for an StrEnum. I suspect they can expose other issues.
encukou commented May 10, 2024
That's false. IMO, we should continue in the direction set in #86667: choices are designed for strings. As Serhiy says, StrEnum aren't well supported in general and may have other issues; that'll also be the case for any other types. |
rindeal commented May 10, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There seems to be some misunderstandings here and there. Therefore, I'll summarize and clarify a few points. This PR should address inaccuracies in both the Premises based on the API documentation:
ReferencesCurrent docs: https://docs.python.org/3/library/argparse.html#choices
|
Uh oh!
There was an error while loading. Please reload this page.
e4ee132 to aea8322Compare
serhiy-storchaka left a comment
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.
LGTM.
This does not solve all issues, but it is an improvement for enums. Good enough.
serhiy-storchaka commented Sep 27, 2024
It would be nice to add a test that uses enums to demonstrate the benefit of this change. |
rindeal commented Sep 28, 2024
Reasonable wish, it’s been granted. |
serhiy-storchaka left a comment
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.
Thank you for your test @rindeal. I have few more comments.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fixes: python#86357 Signed-off-by: Jan Chren ~rindeal <[email protected]>
rindeal commented Oct 14, 2024
@serhiy-storchaka I fixed the conflicts you introduced and implemented all changes you suggested. Please review the updates so it can be finally merged. |
serhiy-storchaka left a comment
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.
Thank you for your update @rindeal.
For future, please do not use rebase. Just stack your changes one over others. This will help to review a PR iteratively, ignoring already reviewed parts. This was not a large issue for this small PR, but it may be a pain for larger PRs.
Thanks @rindeal for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Thanks @rindeal for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @rindeal and @serhiy-storchaka, I could not cleanly backport this to |
Sorry, @rindeal and @serhiy-storchaka, I could not cleanly backport this to |
…y to print choices (pythonGH-117766) (cherry picked from commit 66b3922) Co-authored-by: rindeal <[email protected]> Signed-off-by: Jan Chren ~rindeal <[email protected]>
GH-125431 is a backport of this pull request to the 3.13 branch. |
…y to print choices (pythonGH-117766) (cherry picked from commit 66b3922) Co-authored-by: rindeal <[email protected]> Signed-off-by: Jan Chren ~rindeal <[email protected]>
GH-125432 is a backport of this pull request to the 3.12 branch. |
…rint choices (GH-117766) (GH-125432) (cherry picked from commit 66b3922) Signed-off-by: Jan Chren ~rindeal <[email protected]> Co-authored-by: rindeal <[email protected]>
…rint choices (GH-117766) (GH-125431) (cherry picked from commit 66b3922) Signed-off-by: Jan Chren ~rindeal <[email protected]> Co-authored-by: rindeal <[email protected]>
Due to recent changes in argparse error message construction the test that is checking for the non-existing split algorithm was failing. python/cpython#117766 Fixed with a lenient error string check with additional dynamic algorithm check.
This commit replaces
repr()withstr(), as the former should never be used for normal user-facing printing, and makes it explicit and consistent across the library.For example I tried using
StrEnumfor choices and it printedchoose from <Enum.FOO: 'foo'>, ...instead ofchoose from foo, ....repr()instead ofstr()#118839