Skip to content

Commit 2a8bb31

Browse files
author
Guido van Rossum
committed
Support enum iteration.
Fixes python/mypy#2305.
1 parent 35b6795 commit 2a8bb31

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

stdlib/3.4/enum.pyi

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# FIXME: Stub incomplete, ommissions include:
2-
# * the metaclass
3-
# * _sunder_ methods with their transformations
4-
1+
import abc
52
import sys
6-
from typing import List, Any, TypeVar, Union
3+
from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type
4+
5+
_T = TypeVar('_T', bound=Enum)
76

8-
class Enum:
9-
def __new__(cls, value: Any) -> None: ...
7+
class EnumMeta(abc.ABCMeta, Iterable[Enum]):
8+
def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore
9+
10+
class Enum(metaclass=EnumMeta):
11+
def __new__(cls: Type[_T], value: Any) -> _T: ...
1012
def __repr__(self) -> str: ...
1113
def __str__(self) -> str: ...
1214
def __dir__(self) -> List[str]: ...
@@ -20,8 +22,6 @@ class Enum:
2022
class IntEnum(int, Enum):
2123
value = ... # type: int
2224

23-
_T = TypeVar('_T')
24-
2525
def unique(enumeration: _T) -> _T: ...
2626

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

0 commit comments

Comments
 (0)