From a57e1826083b80fa564e8d46b72981f005bbdd65 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Jul 2022 20:47:37 +0100 Subject: [PATCH] `enum`: Correct `IntFlag` mro on 3.11+ (#8334) --- stdlib/enum.pyi | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 562402671..2ec13714c 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -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):