wrapt 2.1.0.dev1__cp313-cp313t-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wrapt/__init__.py +64 -0
- wrapt/__init__.pyi +319 -0
- wrapt/__wrapt__.py +42 -0
- wrapt/_wrappers.c +4097 -0
- wrapt/_wrappers.cpython-313t-x86_64-linux-musl.so +0 -0
- wrapt/arguments.py +59 -0
- wrapt/decorators.py +522 -0
- wrapt/importer.py +332 -0
- wrapt/patches.py +239 -0
- wrapt/proxies.py +351 -0
- wrapt/py.typed +1 -0
- wrapt/weakrefs.py +114 -0
- wrapt/wrappers.py +980 -0
- wrapt-2.1.0.dev1.dist-info/METADATA +188 -0
- wrapt-2.1.0.dev1.dist-info/RECORD +18 -0
- wrapt-2.1.0.dev1.dist-info/WHEEL +5 -0
- wrapt-2.1.0.dev1.dist-info/licenses/LICENSE +24 -0
- wrapt-2.1.0.dev1.dist-info/top_level.txt +1 -0
wrapt/__init__.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wrapt is a library for decorators, wrappers and monkey patching.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version_info__ = ("2", "1", "0", "dev1")
|
|
6
|
+
__version__ = ".".join(__version_info__)
|
|
7
|
+
|
|
8
|
+
from .__wrapt__ import (
|
|
9
|
+
BaseObjectProxy,
|
|
10
|
+
BoundFunctionWrapper,
|
|
11
|
+
CallableObjectProxy,
|
|
12
|
+
FunctionWrapper,
|
|
13
|
+
PartialCallableObjectProxy,
|
|
14
|
+
partial,
|
|
15
|
+
)
|
|
16
|
+
from .decorators import AdapterFactory, adapter_factory, decorator, synchronized
|
|
17
|
+
from .importer import (
|
|
18
|
+
discover_post_import_hooks,
|
|
19
|
+
notify_module_loaded,
|
|
20
|
+
register_post_import_hook,
|
|
21
|
+
when_imported,
|
|
22
|
+
)
|
|
23
|
+
from .patches import (
|
|
24
|
+
apply_patch,
|
|
25
|
+
function_wrapper,
|
|
26
|
+
patch_function_wrapper,
|
|
27
|
+
resolve_path,
|
|
28
|
+
transient_function_wrapper,
|
|
29
|
+
wrap_function_wrapper,
|
|
30
|
+
wrap_object,
|
|
31
|
+
wrap_object_attribute,
|
|
32
|
+
)
|
|
33
|
+
from .proxies import AutoObjectProxy, LazyObjectProxy, ObjectProxy, lazy_import
|
|
34
|
+
from .weakrefs import WeakFunctionProxy
|
|
35
|
+
|
|
36
|
+
__all__ = (
|
|
37
|
+
"AutoObjectProxy",
|
|
38
|
+
"BaseObjectProxy",
|
|
39
|
+
"BoundFunctionWrapper",
|
|
40
|
+
"CallableObjectProxy",
|
|
41
|
+
"FunctionWrapper",
|
|
42
|
+
"LazyObjectProxy",
|
|
43
|
+
"ObjectProxy",
|
|
44
|
+
"PartialCallableObjectProxy",
|
|
45
|
+
"partial",
|
|
46
|
+
"AdapterFactory",
|
|
47
|
+
"adapter_factory",
|
|
48
|
+
"decorator",
|
|
49
|
+
"synchronized",
|
|
50
|
+
"discover_post_import_hooks",
|
|
51
|
+
"notify_module_loaded",
|
|
52
|
+
"register_post_import_hook",
|
|
53
|
+
"when_imported",
|
|
54
|
+
"apply_patch",
|
|
55
|
+
"function_wrapper",
|
|
56
|
+
"lazy_import",
|
|
57
|
+
"patch_function_wrapper",
|
|
58
|
+
"resolve_path",
|
|
59
|
+
"transient_function_wrapper",
|
|
60
|
+
"wrap_function_wrapper",
|
|
61
|
+
"wrap_object",
|
|
62
|
+
"wrap_object_attribute",
|
|
63
|
+
"WeakFunctionProxy",
|
|
64
|
+
)
|
wrapt/__init__.pyi
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
if sys.version_info >= (3, 10):
|
|
4
|
+
from inspect import FullArgSpec
|
|
5
|
+
from types import ModuleType, TracebackType
|
|
6
|
+
from typing import (
|
|
7
|
+
Any,
|
|
8
|
+
Callable,
|
|
9
|
+
Concatenate,
|
|
10
|
+
Generic,
|
|
11
|
+
ParamSpec,
|
|
12
|
+
Protocol,
|
|
13
|
+
TypeVar,
|
|
14
|
+
overload,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
P = ParamSpec("P")
|
|
18
|
+
R = TypeVar("R", covariant=True)
|
|
19
|
+
|
|
20
|
+
T = TypeVar("T", bound=Any)
|
|
21
|
+
|
|
22
|
+
class Boolean(Protocol):
|
|
23
|
+
def __bool__(self) -> bool: ...
|
|
24
|
+
|
|
25
|
+
# ObjectProxy
|
|
26
|
+
|
|
27
|
+
class BaseObjectProxy(Generic[T]):
|
|
28
|
+
__wrapped__: T
|
|
29
|
+
def __init__(self, wrapped: T) -> None: ...
|
|
30
|
+
|
|
31
|
+
class ObjectProxy(BaseObjectProxy[T]):
|
|
32
|
+
def __init__(self, wrapped: T) -> None: ...
|
|
33
|
+
|
|
34
|
+
class AutoObjectProxy(BaseObjectProxy[T]):
|
|
35
|
+
def __init__(self, wrapped: T) -> None: ...
|
|
36
|
+
|
|
37
|
+
# LazyObjectProxy
|
|
38
|
+
|
|
39
|
+
class LazyObjectProxy(AutoObjectProxy[T]):
|
|
40
|
+
def __init__(
|
|
41
|
+
self, callback: Callable[[], T] | None, *, interface: Any = ...
|
|
42
|
+
) -> None: ...
|
|
43
|
+
|
|
44
|
+
@overload
|
|
45
|
+
def lazy_import(name: str) -> LazyObjectProxy[ModuleType]: ...
|
|
46
|
+
@overload
|
|
47
|
+
def lazy_import(
|
|
48
|
+
name: str, attribute: str, *, interface: Any = ...
|
|
49
|
+
) -> LazyObjectProxy[Any]: ...
|
|
50
|
+
|
|
51
|
+
# CallableObjectProxy
|
|
52
|
+
|
|
53
|
+
class CallableObjectProxy(BaseObjectProxy[T]):
|
|
54
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
|
55
|
+
|
|
56
|
+
# PartialCallableObjectProxy
|
|
57
|
+
|
|
58
|
+
class PartialCallableObjectProxy:
|
|
59
|
+
def __init__(
|
|
60
|
+
self, func: Callable[..., Any], *args: Any, **kwargs: Any
|
|
61
|
+
) -> None: ...
|
|
62
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
|
63
|
+
|
|
64
|
+
def partial(
|
|
65
|
+
func: Callable[..., Any], /, *args: Any, **kwargs: Any
|
|
66
|
+
) -> Callable[..., Any]: ...
|
|
67
|
+
|
|
68
|
+
# WeakFunctionProxy
|
|
69
|
+
|
|
70
|
+
class WeakFunctionProxy:
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
wrapped: Callable[..., Any],
|
|
74
|
+
callback: Callable[..., Any] | None = None,
|
|
75
|
+
) -> None: ...
|
|
76
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
|
77
|
+
|
|
78
|
+
# FunctionWrapper
|
|
79
|
+
|
|
80
|
+
WrappedFunction = Callable[P, R]
|
|
81
|
+
|
|
82
|
+
GenericCallableWrapperFunction = Callable[
|
|
83
|
+
[WrappedFunction[P, R], Any, tuple[Any, ...], dict[str, Any]], R
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
ClassMethodWrapperFunction = Callable[
|
|
87
|
+
[type[Any], WrappedFunction[P, R], Any, tuple[Any, ...], dict[str, Any]], R
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
InstanceMethodWrapperFunction = Callable[
|
|
91
|
+
[Any, WrappedFunction[P, R], Any, tuple[Any, ...], dict[str, Any]], R
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
WrapperFunction = (
|
|
95
|
+
GenericCallableWrapperFunction[P, R]
|
|
96
|
+
| ClassMethodWrapperFunction[P, R]
|
|
97
|
+
| InstanceMethodWrapperFunction[P, R]
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
class _FunctionWrapperBase(ObjectProxy[WrappedFunction[P, R]]):
|
|
101
|
+
_self_instance: Any
|
|
102
|
+
_self_wrapper: WrapperFunction[P, R]
|
|
103
|
+
_self_enabled: bool | Boolean | Callable[[], bool] | None
|
|
104
|
+
_self_binding: str
|
|
105
|
+
_self_parent: Any
|
|
106
|
+
_self_owner: Any
|
|
107
|
+
|
|
108
|
+
class BoundFunctionWrapper(_FunctionWrapperBase[P, R]):
|
|
109
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
110
|
+
def __get__(
|
|
111
|
+
self, instance: Any, owner: type[Any] | None = None
|
|
112
|
+
) -> "BoundFunctionWrapper[P, R]": ...
|
|
113
|
+
|
|
114
|
+
class FunctionWrapper(_FunctionWrapperBase[P, R]):
|
|
115
|
+
def __init__(
|
|
116
|
+
self,
|
|
117
|
+
wrapped: WrappedFunction[P, R],
|
|
118
|
+
wrapper: WrapperFunction[P, R],
|
|
119
|
+
enabled: bool | Boolean | Callable[[], bool] | None = None,
|
|
120
|
+
) -> None: ...
|
|
121
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
122
|
+
def __get__(
|
|
123
|
+
self, instance: Any, owner: type[Any] | None = None
|
|
124
|
+
) -> BoundFunctionWrapper[P, R]: ...
|
|
125
|
+
|
|
126
|
+
# AdapterFactory/adapter_factory()
|
|
127
|
+
|
|
128
|
+
class AdapterFactory(Protocol):
|
|
129
|
+
def __call__(
|
|
130
|
+
self, wrapped: Callable[..., Any]
|
|
131
|
+
) -> str | FullArgSpec | Callable[..., Any]: ...
|
|
132
|
+
|
|
133
|
+
def adapter_factory(wrapped: Callable[..., Any]) -> AdapterFactory: ...
|
|
134
|
+
|
|
135
|
+
# decorator()
|
|
136
|
+
|
|
137
|
+
class Descriptor(Protocol):
|
|
138
|
+
def __get__(self, instance: Any, owner: type[Any] | None = None) -> Any: ...
|
|
139
|
+
|
|
140
|
+
class FunctionDecorator(Generic[P, R]):
|
|
141
|
+
def __call__(
|
|
142
|
+
self,
|
|
143
|
+
callable: (
|
|
144
|
+
Callable[P, R]
|
|
145
|
+
| Callable[Concatenate[type[T], P], R]
|
|
146
|
+
| Callable[Concatenate[Any, P], R]
|
|
147
|
+
| Callable[[type[T]], R]
|
|
148
|
+
| Descriptor
|
|
149
|
+
),
|
|
150
|
+
) -> FunctionWrapper[P, R]: ...
|
|
151
|
+
|
|
152
|
+
class PartialFunctionDecorator:
|
|
153
|
+
@overload
|
|
154
|
+
def __call__(
|
|
155
|
+
self, wrapper: GenericCallableWrapperFunction[P, R], /
|
|
156
|
+
) -> FunctionDecorator[P, R]: ...
|
|
157
|
+
@overload
|
|
158
|
+
def __call__(
|
|
159
|
+
self, wrapper: ClassMethodWrapperFunction[P, R], /
|
|
160
|
+
) -> FunctionDecorator[P, R]: ...
|
|
161
|
+
@overload
|
|
162
|
+
def __call__(
|
|
163
|
+
self, wrapper: InstanceMethodWrapperFunction[P, R], /
|
|
164
|
+
) -> FunctionDecorator[P, R]: ...
|
|
165
|
+
|
|
166
|
+
# ... Decorator applied to class type.
|
|
167
|
+
|
|
168
|
+
@overload
|
|
169
|
+
def decorator(wrapper: type[T], /) -> FunctionDecorator[Any, Any]: ...
|
|
170
|
+
|
|
171
|
+
# ... Decorator applied to function or method.
|
|
172
|
+
|
|
173
|
+
@overload
|
|
174
|
+
def decorator(
|
|
175
|
+
wrapper: GenericCallableWrapperFunction[P, R], /
|
|
176
|
+
) -> FunctionDecorator[P, R]: ...
|
|
177
|
+
@overload
|
|
178
|
+
def decorator(
|
|
179
|
+
wrapper: ClassMethodWrapperFunction[P, R], /
|
|
180
|
+
) -> FunctionDecorator[P, R]: ...
|
|
181
|
+
@overload
|
|
182
|
+
def decorator(
|
|
183
|
+
wrapper: InstanceMethodWrapperFunction[P, R], /
|
|
184
|
+
) -> FunctionDecorator[P, R]: ...
|
|
185
|
+
|
|
186
|
+
# ... Positional arguments.
|
|
187
|
+
|
|
188
|
+
@overload
|
|
189
|
+
def decorator(
|
|
190
|
+
*,
|
|
191
|
+
enabled: bool | Boolean | Callable[[], bool] | None = None,
|
|
192
|
+
adapter: str | FullArgSpec | AdapterFactory | Callable[..., Any] | None = None,
|
|
193
|
+
proxy: type[FunctionWrapper[Any, Any]] | None = None,
|
|
194
|
+
) -> PartialFunctionDecorator: ...
|
|
195
|
+
|
|
196
|
+
# function_wrapper()
|
|
197
|
+
|
|
198
|
+
@overload
|
|
199
|
+
def function_wrapper(wrapper: type[Any]) -> FunctionDecorator[Any, Any]: ...
|
|
200
|
+
@overload
|
|
201
|
+
def function_wrapper(
|
|
202
|
+
wrapper: GenericCallableWrapperFunction[P, R],
|
|
203
|
+
) -> FunctionDecorator[P, R]: ...
|
|
204
|
+
@overload
|
|
205
|
+
def function_wrapper(
|
|
206
|
+
wrapper: ClassMethodWrapperFunction[P, R],
|
|
207
|
+
) -> FunctionDecorator[P, R]: ...
|
|
208
|
+
@overload
|
|
209
|
+
def function_wrapper(
|
|
210
|
+
wrapper: InstanceMethodWrapperFunction[P, R],
|
|
211
|
+
) -> FunctionDecorator[P, R]: ...
|
|
212
|
+
# @overload
|
|
213
|
+
# def function_wrapper(wrapper: Any) -> FunctionDecorator[Any, Any]: ... # Don't use, breaks stuff.
|
|
214
|
+
|
|
215
|
+
# wrap_function_wrapper()
|
|
216
|
+
|
|
217
|
+
def wrap_function_wrapper(
|
|
218
|
+
target: ModuleType | type[Any] | Any | str,
|
|
219
|
+
name: str,
|
|
220
|
+
wrapper: WrapperFunction[P, R],
|
|
221
|
+
) -> FunctionWrapper[P, R]: ...
|
|
222
|
+
|
|
223
|
+
# patch_function_wrapper()
|
|
224
|
+
|
|
225
|
+
class WrapperDecorator:
|
|
226
|
+
def __call__(self, wrapper: WrapperFunction[P, R]) -> FunctionWrapper[P, R]: ...
|
|
227
|
+
|
|
228
|
+
def patch_function_wrapper(
|
|
229
|
+
target: ModuleType | type[Any] | Any | str,
|
|
230
|
+
name: str,
|
|
231
|
+
enabled: bool | Boolean | Callable[[], bool] | None = None,
|
|
232
|
+
) -> WrapperDecorator: ...
|
|
233
|
+
|
|
234
|
+
# transient_function_wrapper()
|
|
235
|
+
|
|
236
|
+
class TransientDecorator:
|
|
237
|
+
def __call__(
|
|
238
|
+
self, wrapper: WrapperFunction[P, R]
|
|
239
|
+
) -> FunctionDecorator[P, R]: ...
|
|
240
|
+
|
|
241
|
+
def transient_function_wrapper(
|
|
242
|
+
target: ModuleType | type[Any] | Any | str, name: str
|
|
243
|
+
) -> TransientDecorator: ...
|
|
244
|
+
|
|
245
|
+
# resolve_path()
|
|
246
|
+
|
|
247
|
+
def resolve_path(
|
|
248
|
+
target: ModuleType | type[Any] | Any | str, name: str
|
|
249
|
+
) -> tuple[ModuleType | type[Any] | Any, str, Callable[..., Any]]: ...
|
|
250
|
+
|
|
251
|
+
# apply_patch()
|
|
252
|
+
|
|
253
|
+
def apply_patch(
|
|
254
|
+
parent: ModuleType | type[Any] | Any,
|
|
255
|
+
attribute: str,
|
|
256
|
+
replacement: Any,
|
|
257
|
+
) -> None: ...
|
|
258
|
+
|
|
259
|
+
# wrap_object()
|
|
260
|
+
|
|
261
|
+
WrapperFactory = Callable[
|
|
262
|
+
[Callable[..., Any], tuple[Any, ...], dict[str, Any]], type[ObjectProxy[Any]]
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
def wrap_object(
|
|
266
|
+
target: ModuleType | type[Any] | Any | str,
|
|
267
|
+
name: str,
|
|
268
|
+
factory: WrapperFactory | type[ObjectProxy[Any]],
|
|
269
|
+
args: tuple[Any, ...],
|
|
270
|
+
kwargs: dict[str, Any],
|
|
271
|
+
) -> Any: ...
|
|
272
|
+
|
|
273
|
+
# wrap_object_attribute()
|
|
274
|
+
|
|
275
|
+
def wrap_object_attribute(
|
|
276
|
+
target: ModuleType | type[Any] | Any | str,
|
|
277
|
+
name: str,
|
|
278
|
+
factory: WrapperFactory | type[ObjectProxy[Any]],
|
|
279
|
+
args: tuple[Any, ...] = (),
|
|
280
|
+
kwargs: dict[str, Any] = {},
|
|
281
|
+
) -> Any: ...
|
|
282
|
+
|
|
283
|
+
# register_post_import_hook()
|
|
284
|
+
|
|
285
|
+
def register_post_import_hook(
|
|
286
|
+
hook: Callable[[ModuleType], Any] | str, name: str
|
|
287
|
+
) -> None: ...
|
|
288
|
+
|
|
289
|
+
# discover_post_import_hooks()
|
|
290
|
+
|
|
291
|
+
def discover_post_import_hooks(group: str) -> None: ...
|
|
292
|
+
|
|
293
|
+
# notify_module_loaded()
|
|
294
|
+
|
|
295
|
+
def notify_module_loaded(module: ModuleType) -> None: ...
|
|
296
|
+
|
|
297
|
+
# when_imported()
|
|
298
|
+
|
|
299
|
+
class ImportHookDecorator:
|
|
300
|
+
def __call__(self, hook: Callable[[ModuleType], Any]) -> Callable[..., Any]: ...
|
|
301
|
+
|
|
302
|
+
def when_imported(name: str) -> ImportHookDecorator: ...
|
|
303
|
+
|
|
304
|
+
# synchronized()
|
|
305
|
+
|
|
306
|
+
class SynchronizedObject:
|
|
307
|
+
def __call__(self, wrapped: Callable[P, R]) -> Callable[P, R]: ...
|
|
308
|
+
def __enter__(self) -> Any: ...
|
|
309
|
+
def __exit__(
|
|
310
|
+
self,
|
|
311
|
+
exc_type: type[BaseException] | None,
|
|
312
|
+
exc_value: BaseException | None,
|
|
313
|
+
traceback: TracebackType | None,
|
|
314
|
+
) -> bool | None: ...
|
|
315
|
+
|
|
316
|
+
@overload
|
|
317
|
+
def synchronized(wrapped: Callable[P, R]) -> Callable[P, R]: ...
|
|
318
|
+
@overload
|
|
319
|
+
def synchronized(wrapped: Any) -> SynchronizedObject: ...
|
wrapt/__wrapt__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""This module is used to switch between C and Python implementations of the
|
|
2
|
+
wrappers.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from .wrappers import BoundFunctionWrapper, CallableObjectProxy, FunctionWrapper
|
|
8
|
+
from .wrappers import ObjectProxy as BaseObjectProxy
|
|
9
|
+
from .wrappers import PartialCallableObjectProxy, _FunctionWrapperBase
|
|
10
|
+
|
|
11
|
+
# Try to use C extensions if not disabled.
|
|
12
|
+
|
|
13
|
+
_using_c_extension = False
|
|
14
|
+
|
|
15
|
+
_use_extensions = not os.environ.get("WRAPT_DISABLE_EXTENSIONS")
|
|
16
|
+
|
|
17
|
+
if _use_extensions:
|
|
18
|
+
try:
|
|
19
|
+
from ._wrappers import ( # type: ignore[no-redef,import-not-found]
|
|
20
|
+
BoundFunctionWrapper,
|
|
21
|
+
CallableObjectProxy,
|
|
22
|
+
FunctionWrapper,
|
|
23
|
+
)
|
|
24
|
+
from ._wrappers import ObjectProxy as BaseObjectProxy # type: ignore[no-redef]
|
|
25
|
+
from ._wrappers import ( # type: ignore[no-redef,import-not-found]
|
|
26
|
+
PartialCallableObjectProxy,
|
|
27
|
+
_FunctionWrapperBase,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
_using_c_extension = True
|
|
31
|
+
except ImportError:
|
|
32
|
+
# C extensions not available, using Python implementations
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def partial(*args, **kwargs):
|
|
37
|
+
"""Create a callable object proxy with partial application of the given
|
|
38
|
+
arguments and keywords. This behaves the same as `functools.partial`, but
|
|
39
|
+
implemented using the `ObjectProxy` class to provide better support for
|
|
40
|
+
introspection.
|
|
41
|
+
"""
|
|
42
|
+
return PartialCallableObjectProxy(*args, **kwargs)
|