3 from abc import ABCMeta
4 from builtins import property as _builtins_property
5 from typing import Any, Iterator, Type, TypeVar
8 _S = TypeVar("_S", bound=Type[Enum])
10 # Note: EnumMeta actually subclasses type directly, not ABCMeta.
11 # This is a temporary workaround to allow multiple creation of enums with builtins
12 # such as str as mixins, which due to the handling of ABCs of builtin types, cause
13 # spurious inconsistent metaclass structure. See #1595.
14 # Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
15 class EnumMeta(ABCMeta):
16 def __iter__(self: Type[_T]) -> Iterator[_T]: ...
17 def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
18 def __contains__(self: Type[Any], member: object) -> bool: ...
19 def __getitem__(self: Type[_T], name: str) -> _T: ...
21 def __members__(self: Type[_T]) -> types.MappingProxyType[str, _T]: ...
22 def __len__(self) -> int: ...
23 _member_names_: list[str] # undocumented
24 _member_map_: dict[str, Enum] # undocumented
25 _value2member_map_: dict[Any, Enum] # undocumented
27 class Enum(metaclass=EnumMeta):
32 if sys.version_info >= (3, 7):
33 _ignore_: str | list[str]
37 def _missing_(cls, value: object) -> Any: ...
39 def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> Any: ...
40 def __new__(cls: Type[_T], value: object) -> _T: ...
41 def __repr__(self) -> str: ...
42 def __str__(self) -> str: ...
43 def __dir__(self) -> list[str]: ...
44 def __format__(self, format_spec: str) -> str: ...
45 def __hash__(self) -> Any: ...
46 def __reduce_ex__(self, proto: object) -> Any: ...
48 class IntEnum(int, Enum):
50 def __new__(cls: Type[_T], value: int | _T) -> _T: ...
52 def unique(enumeration: _S) -> _S: ...
56 # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
59 def __new__(cls: Type[_T]) -> _T: ...
62 name: str | None # type: ignore
64 def __contains__(self: _T, other: _T) -> bool: ...
65 def __repr__(self) -> str: ...
66 def __str__(self) -> str: ...
67 def __bool__(self) -> bool: ...
68 def __or__(self: _T, other: _T) -> _T: ...
69 def __and__(self: _T, other: _T) -> _T: ...
70 def __xor__(self: _T, other: _T) -> _T: ...
71 def __invert__(self: _T) -> _T: ...
73 class IntFlag(int, Flag):
74 def __new__(cls: Type[_T], value: int | _T) -> _T: ...
75 def __or__(self: _T, other: int | _T) -> _T: ...
76 def __and__(self: _T, other: int | _T) -> _T: ...
77 def __xor__(self: _T, other: int | _T) -> _T: ...
78 def __ror__(self: _T, n: int | _T) -> _T: ...
79 def __rand__(self: _T, n: int | _T) -> _T: ...
80 def __rxor__(self: _T, n: int | _T) -> _T: ...
82 if sys.version_info >= (3, 11):
83 class StrEnum(str, Enum):
84 def __new__(cls: Type[_T], value: int | _T) -> _T: ...
85 class FlagBoundary(StrEnum):
90 STRICT = FlagBoundary.STRICT
91 CONFORM = FlagBoundary.CONFORM
92 EJECT = FlagBoundary.EJECT
93 KEEP = FlagBoundary.KEEP
94 class property(_builtins_property): ...
95 def global_enum(cls: _S) -> _S: ...
96 def global_enum_repr(self: Enum) -> str: ...
97 def global_flag_repr(self: Flag) -> str: ...