From 3536e2a080c65cfef17878eae9981b07950848fd Mon Sep 17 00:00:00 2001 From: Maxime Arthaud Date: Wed, 14 Apr 2021 18:41:07 -0700 Subject: [PATCH] Type the constructor of IntEnum and IntFlag (#5217) These should only accept integers or enum members. --- stdlib/enum.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 6a1710faa..9b44bc020 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -45,6 +45,7 @@ class Enum(metaclass=EnumMeta): class IntEnum(int, Enum): value: int + def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ... def unique(enumeration: _S) -> _S: ... @@ -53,6 +54,7 @@ _auto_null: Any # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() class auto(IntFlag): value: Any + def __new__(cls: Type[_T]) -> _T: ... class Flag(Enum): def __contains__(self: _T, other: _T) -> bool: ... @@ -65,6 +67,7 @@ class Flag(Enum): def __invert__(self: _T) -> _T: ... class IntFlag(int, Flag): + def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ... def __or__(self: _T, other: Union[int, _T]) -> _T: ... def __and__(self: _T, other: Union[int, _T]) -> _T: ... def __xor__(self: _T, other: Union[int, _T]) -> _T: ...