gh-115539: Allow enum.Flag to have None members#115636
Conversation
ethanfurman
left a comment
There was a problem hiding this comment.
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 <yurenzhang2017@gmail.com>
|
GH-115694 is a backport of this pull request to the 3.12 branch. |
(cherry picked from commit c2cb31b) Co-authored-by: Jason Zhang <yurenzhang2017@gmail.com>
|
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
Nonemember inenum.Flagcauses 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.