3 from _typeshed import SupportsItems, SupportsLessThan
4 from typing import Any, Callable, Generic, Hashable, Iterable, NamedTuple, Sequence, Sized, Tuple, Type, TypeVar, overload
5 from typing_extensions import final
7 if sys.version_info >= (3, 9):
8 from types import GenericAlias
10 _AnyCallable = Callable[..., Any]
16 def reduce(function: Callable[[_T, _S], _T], sequence: Iterable[_S], initial: _T) -> _T: ...
18 def reduce(function: Callable[[_T, _T], _T], sequence: Iterable[_T]) -> _T: ...
20 class _CacheInfo(NamedTuple):
27 class _lru_cache_wrapper(Generic[_T]):
28 __wrapped__: Callable[..., _T]
29 def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ...
30 def cache_info(self) -> _CacheInfo: ...
31 def cache_clear(self) -> None: ...
33 if sys.version_info >= (3, 8):
35 def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
37 def lru_cache(maxsize: Callable[..., _T], typed: bool = ...) -> _lru_cache_wrapper[_T]: ...
40 def lru_cache(maxsize: int | None = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
42 WRAPPER_ASSIGNMENTS: Sequence[str]
43 WRAPPER_UPDATES: Sequence[str]
45 def update_wrapper(wrapper: _T, wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> _T: ...
46 def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_T], _T]: ...
47 def total_ordering(cls: Type[_T]) -> Type[_T]: ...
48 def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsLessThan]: ...
50 class partial(Generic[_T]):
51 func: Callable[..., _T]
53 keywords: dict[str, Any]
54 def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ...
55 def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
56 if sys.version_info >= (3, 9):
57 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
59 # With protocols, this could change into a generic protocol that defines __get__ and returns _T
62 class partialmethod(Generic[_T]):
63 func: Callable[..., _T] | _Descriptor
65 keywords: dict[str, Any]
67 def __init__(self, __func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ...
69 def __init__(self, __func: _Descriptor, *args: Any, **keywords: Any) -> None: ...
70 def __get__(self, obj: Any, cls: Type[Any]) -> Callable[..., _T]: ...
72 def __isabstractmethod__(self) -> bool: ...
73 if sys.version_info >= (3, 9):
74 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
76 class _SingleDispatchCallable(Generic[_T]):
77 registry: types.MappingProxyType[Any, Callable[..., _T]]
78 def dispatch(self, cls: Any) -> Callable[..., _T]: ...
79 # @fun.register(complex)
80 # def _(arg, verbose=False): ...
82 def register(self, cls: Type[Any], func: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
84 # def _(arg: int, verbose=False):
86 def register(self, cls: Callable[..., _T], func: None = ...) -> Callable[..., _T]: ...
87 # fun.register(int, lambda x: x)
89 def register(self, cls: Type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ...
90 def _clear_cache(self) -> None: ...
91 def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
93 def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ...
95 if sys.version_info >= (3, 8):
96 class singledispatchmethod(Generic[_T]):
97 dispatcher: _SingleDispatchCallable[_T]
98 func: Callable[..., _T]
99 def __init__(self, func: Callable[..., _T]) -> None: ...
101 def register(self, cls: Type[Any], method: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
103 def register(self, cls: Callable[..., _T], method: None = ...) -> Callable[..., _T]: ...
105 def register(self, cls: Type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ...
106 def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
107 class cached_property(Generic[_T]):
108 func: Callable[[Any], _T]
110 def __init__(self, func: Callable[[Any], _T]) -> None: ...
112 def __get__(self, instance: None, owner: Type[Any] | None = ...) -> cached_property[_T]: ...
114 def __get__(self, instance: object, owner: Type[Any] | None = ...) -> _T: ...
115 def __set_name__(self, owner: Type[Any], name: str) -> None: ...
116 if sys.version_info >= (3, 9):
117 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
119 if sys.version_info >= (3, 9):
120 def cache(__user_function: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ...
123 args: Tuple[Hashable, ...],
124 kwds: SupportsItems[Any, Any],
126 kwd_mark: Tuple[object, ...] = ...,
127 fasttypes: set[type] = ...,
130 len: Callable[[Sized], int] = ...,