Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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 ourterms of service andprivacy 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
ghost commentedApr 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 Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
JelleZijlstra commentedApr 19, 2024
Since this changes user-facing behavior, it needs an issue and a NEWS entry. The change in |
rindeal commentedApr 19, 2024
Done
True. But that's a job for |
encukou commentedMay 6, 2024
Since this changes user-facing behavior, it needsan issue. Do you want to file one? As the docs say:
So, in today's As far as I know, |
rindeal commentedMay 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 onthe 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 commentedMay 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 addgh-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 commentedMay 10, 2024
That's false. IMO, we should continue in the direction set in#86667: choices are designed forstrings. 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 commentedMay 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 toaea8322Compare
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 commentedSep 27, 2024
It would be nice to add a test that uses enums to demonstrate the benefit of this change. |
rindeal commentedSep 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#86357Signed-off-by: Jan Chren ~rindeal <dev.rindeal@gmail.com>
rindeal commentedOct 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 commit66b3922)Co-authored-by: rindeal <dev.rindeal@gmail.com>Signed-off-by: Jan Chren ~rindeal <dev.rindeal@gmail.com>
GH-125431 is a backport of this pull request to the3.13 branch. |
…y to print choices (pythonGH-117766)(cherry picked from commit66b3922)Co-authored-by: rindeal <dev.rindeal@gmail.com>Signed-off-by: Jan Chren ~rindeal <dev.rindeal@gmail.com>
GH-125432 is a backport of this pull request to the3.12 branch. |
Due to recent changes in argparse error message construction the testthat is checking for the non-existing split algorithm was failing.python/cpython#117766Fixed with a lenient error string check with additional dynamic algorithmcheck.
Uh oh!
There was an error while loading.Please reload this page.
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