Skip to content

Commit 7027c3e

Browse files
gvanrossumJelleZijlstra
authored andcommitted
Support enum iteration (#1136)
* Support enum iteration. Fixes python/mypy#2305. * Make EnumMeta inherit from type, not ABCMeta.
1 parent 56e7aa6 commit 7027c3e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

stdlib/3.4/enum.pyi

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# FIXME: Stub incomplete, ommissions include:
2-
# * the metaclass
3-
# * _sunder_ methods with their transformations
4-
51
import sys
6-
from typing import List, Any, TypeVar, Union
2+
from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type
3+
4+
_T = TypeVar('_T', bound=Enum)
75

8-
class Enum:
9-
def __new__(cls, value: Any) -> None: ...
6+
class EnumMeta(type, Iterable[Enum]):
7+
def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore
8+
9+
class Enum(metaclass=EnumMeta):
10+
def __new__(cls: Type[_T], value: Any) -> _T: ...
1011
def __repr__(self) -> str: ...
1112
def __str__(self) -> str: ...
1213
def __dir__(self) -> List[str]: ...
@@ -20,8 +21,6 @@ class Enum:
2021
class IntEnum(int, Enum):
2122
value = ... # type: int
2223

23-
_T = TypeVar('_T')
24-
2524
def unique(enumeration: _T) -> _T: ...
2625

2726
if sys.version_info >= (3, 6):

0 commit comments

Comments
 (0)