Skip to content

Commit 3536e2a

Browse files
authored
Type the constructor of IntEnum and IntFlag (#5217)
These should only accept integers or enum members.
1 parent 901b8cb commit 3536e2a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/enum.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Enum(metaclass=EnumMeta):
4545

4646
class IntEnum(int, Enum):
4747
value: int
48+
def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ...
4849

4950
def unique(enumeration: _S) -> _S: ...
5051

@@ -53,6 +54,7 @@ _auto_null: Any
5354
# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
5455
class auto(IntFlag):
5556
value: Any
57+
def __new__(cls: Type[_T]) -> _T: ...
5658

5759
class Flag(Enum):
5860
def __contains__(self: _T, other: _T) -> bool: ...
@@ -65,6 +67,7 @@ class Flag(Enum):
6567
def __invert__(self: _T) -> _T: ...
6668

6769
class IntFlag(int, Flag):
70+
def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ...
6871
def __or__(self: _T, other: Union[int, _T]) -> _T: ...
6972
def __and__(self: _T, other: Union[int, _T]) -> _T: ...
7073
def __xor__(self: _T, other: Union[int, _T]) -> _T: ...

0 commit comments

Comments
 (0)