Skip to content

Commit b41c6da

Browse files
elazargJelleZijlstra
authored andcommitted
Make Enum Iterable (etc.) only structurally (#1755)
Can't express the precise type nominally - see mypy#3210 for details * Make self generic in __contains__
1 parent 0304421 commit b41c6da

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stdlib/3.4/enum.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping
2+
from typing import List, Any, TypeVar, Union, Iterator, TypeVar, Generic, Type, Sized, Mapping
33
from abc import ABCMeta
44

55
_T = TypeVar('_T')
@@ -9,10 +9,11 @@ _S = TypeVar('_S', bound=Type[Enum])
99
# This is a temporary workaround to allow multiple creation of enums with builtins
1010
# such as str as mixins, which due to the handling of ABCs of builtin types, cause
1111
# spurious inconsistent metaclass structure. See #1595.
12-
class EnumMeta(ABCMeta, Iterable[Enum], Sized, Reversible[Enum], Container[Enum]):
12+
# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
13+
class EnumMeta(ABCMeta, Sized):
1314
def __iter__(self: Type[_T]) -> Iterator[_T]: ...
1415
def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
15-
def __contains__(self, member: Any) -> bool: ...
16+
def __contains__(self: Type[_T], member: Any) -> bool: ...
1617
def __getitem__(self: Type[_T], name: str) -> _T: ...
1718
@property
1819
def __members__(self: Type[_T]) -> Mapping[str, _T]: ...

0 commit comments

Comments
 (0)