From 78d9f8e31719798a3eab680095e2a2eb8375441e Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 8 Feb 2017 15:57:49 -0800 Subject: [PATCH 1/2] 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): From abfa7ac457110e37c2d92a94046789508bbd6be1 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 4 Apr 2017 10:13:33 -0700 Subject: [PATCH 2/2] Make EnumMeta inherit from type, not ABCMeta. --- stdlib/3.4/enum.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index 44b7d6c73dea..4f27d33f2f08 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -1,10 +1,9 @@ -import abc import sys from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type _T = TypeVar('_T', bound=Enum) -class EnumMeta(abc.ABCMeta, Iterable[Enum]): +class EnumMeta(type, Iterable[Enum]): def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore class Enum(metaclass=EnumMeta):