From 7027c3e4e8f5d00d5269fc11ccaf768012725abd Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 4 Apr 2017 10:17:52 -0700 Subject: [PATCH] Support enum iteration (#1136) * Support enum iteration. Fixes python/mypy#2305. * Make EnumMeta inherit from type, not ABCMeta. --- stdlib/3.4/enum.pyi | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index 3b97e1be8..4f27d33f2 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -1,12 +1,13 @@ -# FIXME: Stub incomplete, ommissions include: -# * the metaclass -# * _sunder_ methods with their transformations - import sys -from typing import List, Any, TypeVar, Union +from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type -class Enum: - def __new__(cls, value: Any) -> None: ... +_T = TypeVar('_T', bound=Enum) + +class EnumMeta(type, Iterable[Enum]): + def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore + +class Enum(metaclass=EnumMeta): + def __new__(cls: Type[_T], value: Any) -> _T: ... def __repr__(self) -> str: ... def __str__(self) -> str: ... def __dir__(self) -> List[str]: ... @@ -20,8 +21,6 @@ class Enum: class IntEnum(int, Enum): value = ... # type: int -_T = TypeVar('_T') - def unique(enumeration: _T) -> _T: ... if sys.version_info >= (3, 6):