From d5eb32d67e3a975b4588aa8f2d92a1b2ce74fae3 Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Mon, 19 Jun 2017 06:39:56 -0700 Subject: [PATCH] Support iteration over enums with enum34 (#1412) * Support iteration over enums in python 2 * fix lint --- third_party/2/enum.pyi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/third_party/2/enum.pyi b/third_party/2/enum.pyi index 47f89900f..c0b465941 100644 --- a/third_party/2/enum.pyi +++ b/third_party/2/enum.pyi @@ -1,7 +1,11 @@ -from typing import List, Any, TypeVar, Type +from typing import List, Any, TypeVar, Type, Iterable, Iterator -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]: ... @@ -12,8 +16,6 @@ class Enum: name = ... # type: str value = ... # type: Any -_T = TypeVar('_T') - class IntEnum(int, Enum): # type: ignore def __new__(cls: Type[_T], value: Any) -> _T: ...