Add note about IntEnum gotcha#19334
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
| [0, 1] | ||
|
|
||
|
|
||
| Note that the :class:`IntEnum` class is defined by mixing in :class:`int` to :class:`Enum`, which has some surprising |
There was a problem hiding this comment.
This violates our style by describing an intentional design feature as surprising or dangerous. Instead, the devguide states that docs be written affirmatively to show what the tool actually does and how to access its features.
For example, this would be an improvement:
Enumeration support several different display styles:
>>> repr(Color.red)
'<Color.red: 1>'
>>> str(Color.red)
'Color.red'
>>> format(Color.red)
'1'
These three styles can be accessed in f-string as follows:
print(f'{Color.red!r} or {Color.red!s} or {Color.red}' )
|
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 |
|
My apologies for missing this! As of 3.11 the behavior of |


I discovered that
"{}".format(s)on an IntEnum returned a different string thanstr(s).This behavior surprised me (and at least one other person on the Python discord); I figured it'd be good to draw attention to it.