From 6f5199e0db94aeb67349ff5495149e6fc6862cf3 Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Thu, 15 Jun 2017 11:27:25 -0700 Subject: [PATCH 1/2] Support iteration over enums in python 2 --- 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 47f89900f8a9..fd7ca9dc6508 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: ... From 1072816556e8d5467cf629cc2650f82fe74d3476 Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Thu, 15 Jun 2017 11:51:47 -0700 Subject: [PATCH 2/2] fix lint --- third_party/2/enum.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2/enum.pyi b/third_party/2/enum.pyi index fd7ca9dc6508..c0b4659418e2 100644 --- a/third_party/2/enum.pyi +++ b/third_party/2/enum.pyi @@ -2,7 +2,7 @@ from typing import List, Any, TypeVar, Type, Iterable, Iterator _T = TypeVar('_T', bound=Enum) class EnumMeta(type, Iterable[Enum]): - def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore + def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore class Enum(metaclass=EnumMeta): def __new__(cls: Type[_T], value: Any) -> _T: ...