From 88cf09d77165e3b42b0bd60dc0873123c0419e50 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sun, 10 Sep 2017 20:28:43 +0300 Subject: [PATCH] Derive EnumMeta from ABCMeta Avoid inconsistent metaclass structure for enum mixins due to #1595 - e.g. mypy/#2824 --- stdlib/3.4/enum.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/3.4/enum.pyi b/stdlib/3.4/enum.pyi index dbb9df3b7532..148825fe7e98 100644 --- a/stdlib/3.4/enum.pyi +++ b/stdlib/3.4/enum.pyi @@ -1,10 +1,15 @@ import sys from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping +from abc import ABCMeta _T = TypeVar('_T', bound=Enum) _S = TypeVar('_S', bound=Type[Enum]) -class EnumMeta(type, Iterable[Enum], Sized, Reversible[Enum], Container[Enum]): +# Note: EnumMeta actually subclasses type directly, not ABCMeta. +# 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]): def __iter__(self: Type[_T]) -> Iterator[_T]: ... def __reversed__(self: Type[_T]) -> Iterator[_T]: ... def __contains__(self, member: Any) -> bool: ...