From 78d9f8e31719798a3eab680095e2a2eb8375441e Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 8 Feb 2017 15:57:49 -0800 Subject: [PATCH] Support enum iteration. Fixes python/mypy#2305. --- stdlib/3.4/enum.pyi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index 3b97e1be8337..44b7d6c73dea 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -1,12 +1,14 @@ -# FIXME: Stub incomplete, ommissions include: -# * the metaclass -# * _sunder_ methods with their transformations - +import abc import sys -from typing import List, Any, TypeVar, Union +from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type + +_T = TypeVar('_T', bound=Enum) -class Enum: - def __new__(cls, value: Any) -> None: ... +class EnumMeta(abc.ABCMeta, 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 +22,6 @@ class Enum: class IntEnum(int, Enum): value = ... # type: int -_T = TypeVar('_T') - def unique(enumeration: _T) -> _T: ... if sys.version_info >= (3, 6):