enum: Correct IntFlag mro on 3.11+ (#8334)

This commit is contained in:
Alex Waygood
2022-07-19 20:47:37 +01:00
committed by GitHub
parent 5534007189
commit a57e182608

View File

@@ -181,6 +181,8 @@ class Enum(metaclass=EnumMeta):
if sys.version_info >= (3, 11):
class ReprEnum(Enum): ...
if sys.version_info >= (3, 11):
_IntEnumBase = ReprEnum
else:
_IntEnumBase = Enum
@@ -222,14 +224,26 @@ class Flag(Enum):
__rand__ = __and__
__rxor__ = __xor__
class IntFlag(int, Flag):
def __new__(cls: type[Self], value: int) -> Self: ...
def __or__(self: Self, other: int) -> Self: ...
def __and__(self: Self, other: int) -> Self: ...
def __xor__(self: Self, other: int) -> Self: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__
if sys.version_info >= (3, 11):
# The body of the class is the same, but the base classes are different.
class IntFlag(int, ReprEnum, Flag, boundary=KEEP):
def __new__(cls: type[Self], value: int) -> Self: ...
def __or__(self: Self, other: int) -> Self: ...
def __and__(self: Self, other: int) -> Self: ...
def __xor__(self: Self, other: int) -> Self: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__
else:
class IntFlag(int, Flag):
def __new__(cls: type[Self], value: int) -> Self: ...
def __or__(self: Self, other: int) -> Self: ...
def __and__(self: Self, other: int) -> Self: ...
def __xor__(self: Self, other: int) -> Self: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__
if sys.version_info >= (3, 11):
class StrEnum(str, ReprEnum):