1 # NB: third_party/3/enum.pyi and stdlib/3.4/enum.pyi must remain consistent!
\r
3 from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union
\r
4 from abc import ABCMeta
\r
7 _S = TypeVar('_S', bound=Type[Enum])
\r
9 # Note: EnumMeta actually subclasses type directly, not ABCMeta.
\r
10 # This is a temporary workaround to allow multiple creation of enums with builtins
\r
11 # such as str as mixins, which due to the handling of ABCs of builtin types, cause
\r
12 # spurious inconsistent metaclass structure. See #1595.
\r
13 # Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
\r
14 class EnumMeta(ABCMeta):
\r
15 def __iter__(self: Type[_T]) -> Iterator[_T]: ...
\r
16 def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
\r
17 def __contains__(self: Type[_T], member: Any) -> bool: ...
\r
18 def __getitem__(self: Type[_T], name: str) -> _T: ...
\r
20 def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
\r
21 def __len__(self) -> int: ...
\r
23 class Enum(metaclass=EnumMeta):
\r
24 def __new__(cls: Type[_T], value: Any) -> _T: ...
\r
25 def __repr__(self) -> str: ...
\r
26 def __str__(self) -> str: ...
\r
27 def __dir__(self) -> List[str]: ...
\r
28 def __format__(self, format_spec: str) -> str: ...
\r
29 def __hash__(self) -> Any: ...
\r
30 def __reduce_ex__(self, proto: Any) -> Any: ...
\r
32 name = ... # type: str
\r
33 value = ... # type: Any
\r
35 class IntEnum(int, Enum):
\r
36 value = ... # type: int
\r
38 def unique(enumeration: _S) -> _S: ...
\r
40 if sys.version_info >= (3, 6):
\r
41 _auto_null = ... # type: Any
\r
43 # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
\r
44 class auto(IntFlag):
\r
45 value = ... # type: Any
\r
48 def __contains__(self: _T, other: _T) -> bool: ...
\r
49 def __repr__(self) -> str: ...
\r
50 def __str__(self) -> str: ...
\r
51 def __bool__(self) -> bool: ...
\r
52 def __or__(self: _T, other: _T) -> _T: ...
\r
53 def __and__(self: _T, other: _T) -> _T: ...
\r
54 def __xor__(self: _T, other: _T) -> _T: ...
\r
55 def __invert__(self: _T) -> _T: ...
\r
57 # The `type: ignore` comment is needed because mypy considers the type
\r
58 # signatures of several methods defined in int and Flag to be incompatible.
\r
59 class IntFlag(int, Flag): # type: ignore
\r
60 def __or__(self: _T, other: Union[int, _T]) -> _T: ...
\r
61 def __and__(self: _T, other: Union[int, _T]) -> _T: ...
\r
62 def __xor__(self: _T, other: Union[int, _T]) -> _T: ...
\r