Format: application/octet-stream
⬇ Download File (4.5 KB)
   1  import sys
   2  from _typeshed import SupportsLessThan
   3  from typing import (
   4      Any,
   5      Callable,
   6      Dict,
   7      Generic,
   8      Hashable,
   9      Iterable,
  10      Mapping,
  11      NamedTuple,
  12      Optional,
  13      Sequence,
  14      Tuple,
  15      Type,
  16      TypeVar,
  17      Union,
  18      overload,
  19  )
  20  
  21  if sys.version_info >= (3, 9):
  22      from types import GenericAlias
  23  
  24  _AnyCallable = Callable[..., Any]
  25  
  26  _T = TypeVar("_T")
  27  _S = TypeVar("_S")
  28  @overload
  29  def reduce(function: Callable[[_T, _S], _T], sequence: Iterable[_S], initial: _T) -> _T: ...
  30  @overload
  31  def reduce(function: Callable[[_T, _T], _T], sequence: Iterable[_T]) -> _T: ...
  32  
  33  class _CacheInfo(NamedTuple):
  34      hits: int
  35      misses: int
  36      maxsize: int
  37      currsize: int
  38  
  39  class _lru_cache_wrapper(Generic[_T]):
  40      __wrapped__: Callable[..., _T]
  41      def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ...
  42      def cache_info(self) -> _CacheInfo: ...
  43      def cache_clear(self) -> None: ...
  44  
  45  if sys.version_info >= (3, 8):
  46      @overload
  47      def lru_cache(maxsize: Optional[int] = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
  48      @overload
  49      def lru_cache(maxsize: Callable[..., _T], typed: bool = ...) -> _lru_cache_wrapper[_T]: ...
  50  
  51  else:
  52      def lru_cache(maxsize: Optional[int] = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
  53  
  54  WRAPPER_ASSIGNMENTS: Sequence[str]
  55  WRAPPER_UPDATES: Sequence[str]
  56  
  57  def update_wrapper(wrapper: _T, wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> _T: ...
  58  def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_T], _T]: ...
  59  def total_ordering(cls: Type[_T]) -> Type[_T]: ...
  60  def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsLessThan]: ...
  61  
  62  class partial(Generic[_T]):
  63      func: Callable[..., _T]
  64      args: Tuple[Any, ...]
  65      keywords: Dict[str, Any]
  66      def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ...
  67      def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
  68      if sys.version_info >= (3, 9):
  69          def __class_getitem__(cls, item: Any) -> GenericAlias: ...
  70  
  71  # With protocols, this could change into a generic protocol that defines __get__ and returns _T
  72  _Descriptor = Any
  73  
  74  class partialmethod(Generic[_T]):
  75      func: Union[Callable[..., _T], _Descriptor]
  76      args: Tuple[Any, ...]
  77      keywords: Dict[str, Any]
  78      @overload
  79      def __init__(self, __func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ...
  80      @overload
  81      def __init__(self, __func: _Descriptor, *args: Any, **keywords: Any) -> None: ...
  82      def __get__(self, obj: Any, cls: Type[Any]) -> Callable[..., _T]: ...
  83      @property
  84      def __isabstractmethod__(self) -> bool: ...
  85      if sys.version_info >= (3, 9):
  86          def __class_getitem__(cls, item: Any) -> GenericAlias: ...
  87  
  88  class _SingleDispatchCallable(Generic[_T]):
  89      registry: Mapping[Any, Callable[..., _T]]
  90      def dispatch(self, cls: Any) -> Callable[..., _T]: ...
  91      @overload
  92      def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
  93      @overload
  94      def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ...
  95      def _clear_cache(self) -> None: ...
  96      def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
  97  
  98  def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ...
  99  
 100  if sys.version_info >= (3, 8):
 101      class singledispatchmethod(Generic[_T]):
 102          dispatcher: _SingleDispatchCallable[_T]
 103          func: Callable[..., _T]
 104          def __init__(self, func: Callable[..., _T]) -> None: ...
 105          @overload
 106          def register(self, cls: Any, method: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
 107          @overload
 108          def register(self, cls: Any, method: Callable[..., _T]) -> Callable[..., _T]: ...
 109          def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
 110      class cached_property(Generic[_T]):
 111          func: Callable[[Any], _T]
 112          attrname: Optional[str]
 113          def __init__(self, func: Callable[[Any], _T]) -> None: ...
 114          @overload
 115          def __get__(self, instance: None, owner: Optional[Type[Any]] = ...) -> cached_property[_T]: ...
 116          @overload
 117          def __get__(self, instance: _S, owner: Optional[Type[Any]] = ...) -> _T: ...
 118          def __set_name__(self, owner: Type[Any], name: str) -> None: ...
 119          if sys.version_info >= (3, 9):
 120              def __class_getitem__(cls, item: Any) -> GenericAlias: ...
 121  
 122  if sys.version_info >= (3, 9):
 123      def cache(__user_function: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ...
 124