Format: application/octet-stream
⬇ Download File (2.6 KB)
   1  import sys
   2  from abc import ABCMeta
   3  from typing import Any, Dict, Iterator, List, Mapping, Type, TypeVar, Union
   4  
   5  _T = TypeVar("_T")
   6  _S = TypeVar("_S", bound=Type[Enum])
   7  
   8  # Note: EnumMeta actually subclasses type directly, not ABCMeta.
   9  # This is a temporary workaround to allow multiple creation of enums with builtins
  10  # such as str as mixins, which due to the handling of ABCs of builtin types, cause
  11  # spurious inconsistent metaclass structure. See #1595.
  12  # Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
  13  class EnumMeta(ABCMeta):
  14      def __iter__(self: Type[_T]) -> Iterator[_T]: ...
  15      def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
  16      def __contains__(self: Type[_T], member: object) -> bool: ...
  17      def __getitem__(self: Type[_T], name: str) -> _T: ...
  18      @property
  19      def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
  20      def __len__(self) -> int: ...
  21  
  22  class Enum(metaclass=EnumMeta):
  23      name: str
  24      value: Any
  25      _name_: str
  26      _value_: Any
  27      _member_names_: List[str]  # undocumented
  28      _member_map_: Dict[str, Enum]  # undocumented
  29      _value2member_map_: Dict[int, Enum]  # undocumented
  30      if sys.version_info >= (3, 7):
  31          _ignore_: Union[str, List[str]]
  32      _order_: str
  33      __order__: str
  34      @classmethod
  35      def _missing_(cls, value: object) -> Any: ...
  36      @staticmethod
  37      def _generate_next_value_(name: str, start: int, count: int, last_values: List[Any]) -> Any: ...
  38      def __new__(cls: Type[_T], value: object) -> _T: ...
  39      def __repr__(self) -> str: ...
  40      def __str__(self) -> str: ...
  41      def __dir__(self) -> List[str]: ...
  42      def __format__(self, format_spec: str) -> str: ...
  43      def __hash__(self) -> Any: ...
  44      def __reduce_ex__(self, proto: object) -> Any: ...
  45  
  46  class IntEnum(int, Enum):
  47      value: int
  48  
  49  def unique(enumeration: _S) -> _S: ...
  50  
  51  _auto_null: Any
  52  
  53  # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
  54  class auto(IntFlag):
  55      value: Any
  56  
  57  class Flag(Enum):
  58      def __contains__(self: _T, other: _T) -> bool: ...
  59      def __repr__(self) -> str: ...
  60      def __str__(self) -> str: ...
  61      def __bool__(self) -> bool: ...
  62      def __or__(self: _T, other: _T) -> _T: ...
  63      def __and__(self: _T, other: _T) -> _T: ...
  64      def __xor__(self: _T, other: _T) -> _T: ...
  65      def __invert__(self: _T) -> _T: ...
  66  
  67  class IntFlag(int, Flag):
  68      def __or__(self: _T, other: Union[int, _T]) -> _T: ...
  69      def __and__(self: _T, other: Union[int, _T]) -> _T: ...
  70      def __xor__(self: _T, other: Union[int, _T]) -> _T: ...
  71      __ror__ = __or__
  72      __rand__ = __and__
  73      __rxor__ = __xor__
  74