-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-115539: Allow enum.Flag to have None members #115636
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
Conversation
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.
Looks good so far, but we need to also handle cases where the None
flag is combined with other flags. Currently it looks like:
>>> Huh.A | Huh.Z # A = 1, Z = None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Huh.A | Huh.Z
~~~~~~^~~~~~~
File "/source/python/cpython/Lib/enum.py", line 1571, in __or__
return self.__class__(value | other)
~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for |: 'int' and 'NoneType'
I think a TypeError
is fine, but it needs a better error message.
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 |
c24254a
to
1416fec
Compare
I have made the requested changes; please review again |
@ethanfurman Thanks for the quick review! Shall I add a News entry or shall we skip news? |
We'll skip news and backport. |
Thanks @Jason-Y-Z for the PR, and @ethanfurman for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
(cherry picked from commit c2cb31b) Co-authored-by: Jason Zhang <[email protected]>
GH-115694 is a backport of this pull request to the 3.12 branch. |
(cherry picked from commit c2cb31b) Co-authored-by: Jason Zhang <[email protected]>
GH-115695 is a backport of this pull request to the 3.11 branch. |
This PR addresses the issue mentioned in Issue #115539 , where having a
None
member inenum.Flag
causes an Exception.The approach taken is simply to add a
isinstance(_, int)
check before using the member's value, at 2 relevant places.This is a small addition so probably can skip-news.