Debian Codegraph @

jaraco/functools/__init__.pyi

raw symbols SCIP
1 from collections.abc import Callable, Hashable, Iterator
2 from functools import partial
3 from operator import methodcaller
4 import sys
5 from typing import (
6 Any,
7 Generic,
8 Protocol,
9 TypeVar,
10 overload,
11 )
12
13 if sys.version_info >= (3, 10):
14 from typing import Concatenate, ParamSpec
15 else:
16 from typing_extensions import Concatenate, ParamSpec
17
18 _P = ParamSpec('_P')
19 _R = TypeVar('_R')
20 _T = TypeVar('_T')
21 _R1 = TypeVar('_R1')
22 _R2 = TypeVar('_R2')
23 _V = TypeVar('_V')
24 _S = TypeVar('_S')
25 _R_co = TypeVar('_R_co', covariant=True)
26
27 class _OnceCallable(Protocol[_P, _R]):
28 saved_result: _R
29 reset: Callable[[], None]
30 def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
31
32 class _ProxyMethodCacheWrapper(Protocol[_R_co]):
33 cache_clear: Callable[[], None]
34 def __call__(self, *args: Hashable, **kwargs: Hashable) -> _R_co: ...
35
36 class _MethodCacheWrapper(Protocol[_R_co]):
37 def cache_clear(self) -> None: ...
38 def __call__(self, *args: Hashable, **kwargs: Hashable) -> _R_co: ...
39
40 # `compose()` overloads below will cover most use cases.
41
42 @overload
43 def compose(
44 __func1: Callable[[_R], _T],
45 __func2: Callable[_P, _R],
46 /,
47 ) -> Callable[_P, _T]: ...
48 @overload
49 def compose(
50 __func1: Callable[[_R], _T],
51 __func2: Callable[[_R1], _R],
52 __func3: Callable[_P, _R1],
53 /,
54 ) -> Callable[_P, _T]: ...
55 @overload
56 def compose(
57 __func1: Callable[[_R], _T],
58 __func2: Callable[[_R2], _R],
59 __func3: Callable[[_R1], _R2],
60 __func4: Callable[_P, _R1],
61 /,
62 ) -> Callable[_P, _T]: ...
63 def once(func: Callable[_P, _R]) -> _OnceCallable[_P, _R]: ...
64 def method_cache(
65 method: Callable[..., _R],
66 cache_wrapper: Callable[[Callable[..., _R]], _MethodCacheWrapper[_R]] = ...,
67 ) -> _MethodCacheWrapper[_R] | _ProxyMethodCacheWrapper[_R]: ...
68 def apply(
69 transform: Callable[[_R], _T]
70 ) -> Callable[[Callable[_P, _R]], Callable[_P, _T]]: ...
71 def result_invoke(
72 action: Callable[[_R], Any]
73 ) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
74 def invoke(
75 f: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs
76 ) -> Callable[_P, _R]: ...
77
78 class Throttler(Generic[_R]):
79 last_called: float
80 func: Callable[..., _R]
81 max_rate: float
82 def __init__(
83 self, func: Callable[..., _R] | Throttler[_R], max_rate: float = ...
84 ) -> None: ...
85 def reset(self) -> None: ...
86 def __call__(self, *args: Any, **kwargs: Any) -> _R: ...
87 def __get__(self, obj: Any, owner: type[Any] | None = ...) -> Callable[..., _R]: ...
88
89 def first_invoke(
90 func1: Callable[..., Any], func2: Callable[_P, _R]
91 ) -> Callable[_P, _R]: ...
92
93 method_caller: Callable[..., methodcaller]
94
95 def retry_call(
96 func: Callable[..., _R],
97 cleanup: Callable[..., None] = ...,
98 retries: int | float = ...,
99 trap: type[BaseException] | tuple[type[BaseException], ...] = ...,
100 ) -> _R: ...
101 def retry(
102 cleanup: Callable[..., None] = ...,
103 retries: int | float = ...,
104 trap: type[BaseException] | tuple[type[BaseException], ...] = ...,
105 ) -> Callable[[Callable[..., _R]], Callable[..., _R]]: ...
106 def print_yielded(func: Callable[_P, Iterator[Any]]) -> Callable[_P, None]: ...
107 def pass_none(
108 func: Callable[Concatenate[_T, _P], _R]
109 ) -> Callable[Concatenate[_T, _P], _R]: ...
110 def assign_params(
111 func: Callable[..., _R], namespace: dict[str, Any]
112 ) -> partial[_R]: ...
113 def save_method_args(
114 method: Callable[Concatenate[_S, _P], _R]
115 ) -> Callable[Concatenate[_S, _P], _R]: ...
116 def except_(
117 *exceptions: type[BaseException], replace: Any = ..., use: Any = ...
118 ) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ...
119 def identity(x: _T) -> _T: ...
120 def bypass_when(
121 check: _V, *, _op: Callable[[_V], Any] = ...
122 ) -> Callable[[Callable[[_T], _R]], Callable[[_T], _T | _R]]: ...
123 def bypass_unless(
124 check: Any,
125 ) -> Callable[[Callable[[_T], _R]], Callable[[_T], _T | _R]]: ...