mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist (#106468)
For example: class Flag(enum.Flag): A = 0x01 B = 0x02 MASK = 0xff ~Flag.MASK is Flag(0)
This commit is contained in:
parent
af5cf1e751
commit
95b7426f45
3 changed files with 86 additions and 61 deletions
|
@ -1515,14 +1515,10 @@ class Flag(Enum, boundary=STRICT):
|
|||
|
||||
def __invert__(self):
|
||||
if self._inverted_ is None:
|
||||
if self._boundary_ is KEEP:
|
||||
# use all bits
|
||||
if self._boundary_ in (EJECT, KEEP):
|
||||
self._inverted_ = self.__class__(~self._value_)
|
||||
else:
|
||||
# use canonical bits (i.e. calculate flags not in this member)
|
||||
self._inverted_ = self.__class__(self._singles_mask_ ^ self._value_)
|
||||
if isinstance(self._inverted_, self.__class__):
|
||||
self._inverted_._inverted_ = self
|
||||
self._inverted_ = self.__class__(self._singles_mask_ & ~self._value_)
|
||||
return self._inverted_
|
||||
|
||||
__rand__ = __and__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue