From 1c8ed307ef3019ef5f583306760b51ecde7b29c8 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 20 Nov 2017 22:38:58 +0200 Subject: [PATCH 1/2] Make Enum Iterable (etc.) only by structurally Can't express the precise type nominally - see mypy#3210 for details --- stdlib/3.4/enum.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index 1501be27450e..9f63db01382d 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -1,5 +1,5 @@ import sys -from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping +from typing import List, Any, TypeVar, Union, Iterator, TypeVar, Generic, Type, Sized, Mapping from abc import ABCMeta _T = TypeVar('_T', bound=Enum) @@ -9,7 +9,8 @@ _S = TypeVar('_S', bound=Type[Enum]) # This is a temporary workaround to allow multiple creation of enums with builtins # such as str as mixins, which due to the handling of ABCs of builtin types, cause # spurious inconsistent metaclass structure. See #1595. -class EnumMeta(ABCMeta, Iterable[Enum], Sized, Reversible[Enum], Container[Enum]): +# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself +class EnumMeta(ABCMeta, Sized): def __iter__(self: Type[_T]) -> Iterator[_T]: ... def __reversed__(self: Type[_T]) -> Iterator[_T]: ... def __contains__(self, member: Any) -> bool: ... From 55a6f8fd047f4c9684230834cb7c050e44e8a5b1 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Tue, 21 Nov 2017 01:04:38 +0200 Subject: [PATCH 2/2] Make self generic in __contains__ --- stdlib/3.4/enum.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index 9f63db01382d..48f433e83328 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -13,7 +13,7 @@ _S = TypeVar('_S', bound=Type[Enum]) class EnumMeta(ABCMeta, Sized): def __iter__(self: Type[_T]) -> Iterator[_T]: ... def __reversed__(self: Type[_T]) -> Iterator[_T]: ... - def __contains__(self, member: Any) -> bool: ... + def __contains__(self: Type[_T], member: Any) -> bool: ... def __getitem__(self: Type[_T], name: str) -> _T: ... @property def __members__(self: Type[_T]) -> Mapping[str, _T]: ...