mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 14:01:55 +08:00
Make PY2 enum more like PY3 enum, fixing bug in unique() (#1668)
This commit is contained in:
committed by
Matthias Kramm
parent
c366a1be55
commit
994cfb5369
20
third_party/2/enum.pyi
vendored
20
third_party/2/enum.pyi
vendored
@@ -1,8 +1,20 @@
|
||||
from typing import List, Any, TypeVar, Type, Iterable, Iterator
|
||||
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)
|
||||
class EnumMeta(type, Iterable[Enum]):
|
||||
def __iter__(self: Type[_T]) -> Iterator[_T]: ... # type: ignore
|
||||
_S = TypeVar('_S', bound=Type[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: ...
|
||||
def __getitem__(self: Type[_T], name: str) -> _T: ...
|
||||
@property
|
||||
def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
|
||||
|
||||
class Enum(metaclass=EnumMeta):
|
||||
def __new__(cls: Type[_T], value: Any) -> _T: ...
|
||||
@@ -18,4 +30,4 @@ class Enum(metaclass=EnumMeta):
|
||||
|
||||
class IntEnum(int, Enum): ...
|
||||
|
||||
def unique(enumeration: _T) -> _T: ...
|
||||
def unique(enumeration: _S) -> _S: ...
|
||||
|
||||
Reference in New Issue
Block a user