Sorry, something went wrong.
Sorry, something went wrong.
|
@JosephSBoyle thank you! I've added your changes. Let me know if there is anything else needed from my side. Should I also open a PR against the 3.11 branch? |
Sorry, something went wrong.
|
@anze3db No need, once this is committed a backport PR will be automatically created. |
Sorry, something went wrong.
|
@JosephSBoyle there was more than a month of inactivity on this PR 😞 Anything I can do to help this getting merged? |
Sorry, something went wrong.
|
Hi @anze3db, I'm not a maintainer so perhaps this is a better question for @AlexWaygood. If the assigned reviewer is busy perhaps another reviewer can be assigned. |
Sorry, something went wrong.
|
Will this PR finds its way to the next version of Python? Further question: is this change documented here https://docs.python.org/3/library/enum.html ? I can't spot it... |
Sorry, something went wrong.
There was a problem hiding this comment.
My apologies -- I didn't get the [Submit Review] button pressed.
Sorry, something went wrong.
| (the default for :func:`format`, :meth:`str.format` and :term:`f-string`\s) | ||
| of enums with mixed-in types (e.g. :class:`int`, :class:`str`) | ||
| to also include the class name in the output, not just the member's key. | ||
| to include the class name and member key in the output, not the member's value. |
There was a problem hiding this comment.
| to include the class name and member key in the output, not the member's value. | |
| to show the class name and member name in the output, instead of the member's value. |
Sorry, something went wrong.
| to also include the class name in the output, not just the member's key. | ||
| to include the class name and member key in the output, not the member's value. | ||
| This matches the existing behavior of :meth:`enum.Enum.__str__`, | ||
| returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` |
There was a problem hiding this comment.
| returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` | |
| returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``. |
Sorry, something went wrong.
| This matches the existing behavior of :meth:`enum.Enum.__str__`, | ||
| returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` | ||
| instead of just ``'MEMBER'``. | ||
| instead of the member's value. Those wishing to keep the old formatting behavior |
There was a problem hiding this comment.
| instead of the member's value. Those wishing to keep the old formatting behavior | |
| Those wishing to keep the old formatting behavior |
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
|
I have made the requested changes; please review again. |
Sorry, something went wrong.
|
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
Sorry, something went wrong.
|
@ethanfurman just a friendly reminder to re-review this if you have the time, thanks! |
Sorry, something went wrong.
There was a problem hiding this comment.
Did some rewriting in an attempt to make it clearer.
Thoughts on the new changes?
Sorry, something went wrong.
|
Thanks @anze3db for the PR, and @ethanfurman for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
|
GH-104060 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
Hey! 👋
Please correct me if I'm wrong, but the description of the change Enum.format() change in 3.11.rst doesn't seem accurate. The behavior in older Python versions was to return the member's value and not the member's key as is currently stated. Example code:
Running this on Python 3.10 prints:
And not
as the changelog states:
Changed Enum.format() (the default for format(), str.format() and f-strings) of enums with mixed-in types (e.g. int, str) to also include the class name in the output, not just the member’s key. This matches the existing behavior of enum.Enum.str(), returning e.g. 'AnEnum.MEMBER' for an enum AnEnum(str, Enum) instead of just 'MEMBER'.
I noticed this because we were using the str mixin with all Enum classes as a hack to get to the value without needing to write Foo.BAR.value 🫣 The new behavior in Python 3.11 broke our code and the current phrasing in the changelog makes it feel this was just a minor bugfix. Should this change be a bit more prominent since it can be a breaking change?
By the way, thank you for adding StrEnum, it's exactly what we needed!
PS: Not sure if this needs a GitHub issue number, it's not exactly a typo, but it's still a minor change. I'm happy to open an issue if needed. Issue linked below. Also let me know if I need to open the PR against any other branches as well. 🙇