ez-a-sync 0.32.29__cp310-cp310-win_amd64.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.
Potentially problematic release.
This version of ez-a-sync might be problematic. Click here for more details.
- a_sync/ENVIRONMENT_VARIABLES.py +42 -0
- a_sync/__init__.pxd +2 -0
- a_sync/__init__.py +145 -0
- a_sync/_smart.c +22803 -0
- a_sync/_smart.cp310-win_amd64.pyd +0 -0
- a_sync/_smart.pxd +2 -0
- a_sync/_smart.pyi +202 -0
- a_sync/_smart.pyx +674 -0
- a_sync/_typing.py +258 -0
- a_sync/a_sync/__init__.py +60 -0
- a_sync/a_sync/_descriptor.c +20528 -0
- a_sync/a_sync/_descriptor.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_descriptor.pyi +33 -0
- a_sync/a_sync/_descriptor.pyx +422 -0
- a_sync/a_sync/_flags.c +6074 -0
- a_sync/a_sync/_flags.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_flags.pxd +3 -0
- a_sync/a_sync/_flags.pyx +92 -0
- a_sync/a_sync/_helpers.c +14521 -0
- a_sync/a_sync/_helpers.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_helpers.pxd +3 -0
- a_sync/a_sync/_helpers.pyi +10 -0
- a_sync/a_sync/_helpers.pyx +167 -0
- a_sync/a_sync/_kwargs.c +12194 -0
- a_sync/a_sync/_kwargs.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_kwargs.pxd +2 -0
- a_sync/a_sync/_kwargs.pyx +64 -0
- a_sync/a_sync/_meta.py +210 -0
- a_sync/a_sync/abstract.c +12411 -0
- a_sync/a_sync/abstract.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/abstract.pyi +141 -0
- a_sync/a_sync/abstract.pyx +221 -0
- a_sync/a_sync/base.c +14932 -0
- a_sync/a_sync/base.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/base.pyi +60 -0
- a_sync/a_sync/base.pyx +271 -0
- a_sync/a_sync/config.py +168 -0
- a_sync/a_sync/decorator.py +651 -0
- a_sync/a_sync/flags.c +5272 -0
- a_sync/a_sync/flags.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/flags.pxd +72 -0
- a_sync/a_sync/flags.pyi +74 -0
- a_sync/a_sync/flags.pyx +72 -0
- a_sync/a_sync/function.c +37846 -0
- a_sync/a_sync/function.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/function.pxd +28 -0
- a_sync/a_sync/function.pyi +571 -0
- a_sync/a_sync/function.pyx +1381 -0
- a_sync/a_sync/method.c +29774 -0
- a_sync/a_sync/method.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/method.pxd +9 -0
- a_sync/a_sync/method.pyi +525 -0
- a_sync/a_sync/method.pyx +1023 -0
- a_sync/a_sync/modifiers/__init__.pxd +1 -0
- a_sync/a_sync/modifiers/__init__.py +101 -0
- a_sync/a_sync/modifiers/cache/__init__.py +160 -0
- a_sync/a_sync/modifiers/cache/memory.py +165 -0
- a_sync/a_sync/modifiers/limiter.py +132 -0
- a_sync/a_sync/modifiers/manager.c +16149 -0
- a_sync/a_sync/modifiers/manager.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/modifiers/manager.pxd +5 -0
- a_sync/a_sync/modifiers/manager.pyi +219 -0
- a_sync/a_sync/modifiers/manager.pyx +299 -0
- a_sync/a_sync/modifiers/semaphores.py +173 -0
- a_sync/a_sync/property.c +27260 -0
- a_sync/a_sync/property.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/property.pyi +376 -0
- a_sync/a_sync/property.pyx +819 -0
- a_sync/a_sync/singleton.py +63 -0
- a_sync/aliases.py +3 -0
- a_sync/async_property/__init__.pxd +1 -0
- a_sync/async_property/__init__.py +1 -0
- a_sync/async_property/cached.c +20386 -0
- a_sync/async_property/cached.cp310-win_amd64.pyd +0 -0
- a_sync/async_property/cached.pxd +10 -0
- a_sync/async_property/cached.pyi +45 -0
- a_sync/async_property/cached.pyx +178 -0
- a_sync/async_property/proxy.c +34654 -0
- a_sync/async_property/proxy.cp310-win_amd64.pyd +0 -0
- a_sync/async_property/proxy.pxd +2 -0
- a_sync/async_property/proxy.pyi +124 -0
- a_sync/async_property/proxy.pyx +474 -0
- a_sync/asyncio/__init__.pxd +6 -0
- a_sync/asyncio/__init__.py +164 -0
- a_sync/asyncio/as_completed.c +18841 -0
- a_sync/asyncio/as_completed.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/as_completed.pxd +8 -0
- a_sync/asyncio/as_completed.pyi +109 -0
- a_sync/asyncio/as_completed.pyx +269 -0
- a_sync/asyncio/create_task.c +15902 -0
- a_sync/asyncio/create_task.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/create_task.pxd +2 -0
- a_sync/asyncio/create_task.pyi +51 -0
- a_sync/asyncio/create_task.pyx +271 -0
- a_sync/asyncio/gather.c +16679 -0
- a_sync/asyncio/gather.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/gather.pyi +107 -0
- a_sync/asyncio/gather.pyx +218 -0
- a_sync/asyncio/igather.c +12676 -0
- a_sync/asyncio/igather.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/igather.pxd +1 -0
- a_sync/asyncio/igather.pyi +7 -0
- a_sync/asyncio/igather.pyx +182 -0
- a_sync/asyncio/sleep.c +9593 -0
- a_sync/asyncio/sleep.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/sleep.pyi +14 -0
- a_sync/asyncio/sleep.pyx +49 -0
- a_sync/debugging.c +15362 -0
- a_sync/debugging.cp310-win_amd64.pyd +0 -0
- a_sync/debugging.pyi +76 -0
- a_sync/debugging.pyx +107 -0
- a_sync/exceptions.c +13312 -0
- a_sync/exceptions.cp310-win_amd64.pyd +0 -0
- a_sync/exceptions.pyi +376 -0
- a_sync/exceptions.pyx +446 -0
- a_sync/executor.py +619 -0
- a_sync/functools.c +12738 -0
- a_sync/functools.cp310-win_amd64.pyd +0 -0
- a_sync/functools.pxd +7 -0
- a_sync/functools.pyi +33 -0
- a_sync/functools.pyx +139 -0
- a_sync/future.py +1497 -0
- a_sync/iter.c +37271 -0
- a_sync/iter.cp310-win_amd64.pyd +0 -0
- a_sync/iter.pxd +11 -0
- a_sync/iter.pyi +370 -0
- a_sync/iter.pyx +981 -0
- a_sync/primitives/__init__.pxd +1 -0
- a_sync/primitives/__init__.py +53 -0
- a_sync/primitives/_debug.c +15757 -0
- a_sync/primitives/_debug.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/_debug.pxd +12 -0
- a_sync/primitives/_debug.pyi +52 -0
- a_sync/primitives/_debug.pyx +223 -0
- a_sync/primitives/_loggable.c +11529 -0
- a_sync/primitives/_loggable.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/_loggable.pxd +4 -0
- a_sync/primitives/_loggable.pyi +66 -0
- a_sync/primitives/_loggable.pyx +102 -0
- a_sync/primitives/locks/__init__.pxd +8 -0
- a_sync/primitives/locks/__init__.py +17 -0
- a_sync/primitives/locks/counter.c +17679 -0
- a_sync/primitives/locks/counter.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/counter.pxd +12 -0
- a_sync/primitives/locks/counter.pyi +151 -0
- a_sync/primitives/locks/counter.pyx +260 -0
- a_sync/primitives/locks/event.c +17063 -0
- a_sync/primitives/locks/event.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/event.pxd +22 -0
- a_sync/primitives/locks/event.pyi +43 -0
- a_sync/primitives/locks/event.pyx +185 -0
- a_sync/primitives/locks/prio_semaphore.c +25590 -0
- a_sync/primitives/locks/prio_semaphore.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/prio_semaphore.pxd +25 -0
- a_sync/primitives/locks/prio_semaphore.pyi +217 -0
- a_sync/primitives/locks/prio_semaphore.pyx +597 -0
- a_sync/primitives/locks/semaphore.c +26509 -0
- a_sync/primitives/locks/semaphore.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/semaphore.pxd +21 -0
- a_sync/primitives/locks/semaphore.pyi +197 -0
- a_sync/primitives/locks/semaphore.pyx +454 -0
- a_sync/primitives/queue.py +1022 -0
- a_sync/py.typed +0 -0
- a_sync/sphinx/__init__.py +3 -0
- a_sync/sphinx/ext.py +289 -0
- a_sync/task.py +932 -0
- a_sync/utils/__init__.py +105 -0
- a_sync/utils/iterators.py +297 -0
- a_sync/utils/repr.c +15799 -0
- a_sync/utils/repr.cp310-win_amd64.pyd +0 -0
- a_sync/utils/repr.pyi +2 -0
- a_sync/utils/repr.pyx +73 -0
- ez_a_sync-0.32.29.dist-info/METADATA +367 -0
- ez_a_sync-0.32.29.dist-info/RECORD +177 -0
- ez_a_sync-0.32.29.dist-info/WHEEL +5 -0
- ez_a_sync-0.32.29.dist-info/licenses/LICENSE.txt +17 -0
- ez_a_sync-0.32.29.dist-info/top_level.txt +1 -0
|
Binary file
|
a_sync/a_sync/method.pxd
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from a_sync.a_sync.function cimport _ASyncFunction
|
|
2
|
+
cdef class _ASyncBoundMethod(_ASyncFunction):
|
|
3
|
+
cdef readonly object __weakself__
|
|
4
|
+
cdef readonly bint _is_async_def
|
|
5
|
+
cdef readonly object _cache_handle
|
|
6
|
+
cdef object c_map(self, tuple iterables, object concurrency, str task_name, dict kwargs)
|
|
7
|
+
cdef object __c_self__(self)
|
|
8
|
+
cdef bint _is_a_sync_instance(object instance)
|
|
9
|
+
cdef void _update_cache_timer(str field_name, object instance, _ASyncBoundMethod bound)
|
a_sync/a_sync/method.pyi
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides classes for implementing dual-functional sync/async methods in Python.
|
|
3
|
+
|
|
4
|
+
It includes descriptors and bound methods that can be used to create flexible
|
|
5
|
+
asynchronous interfaces, allowing methods to be called both synchronously and
|
|
6
|
+
asynchronously based on various conditions and configurations.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from a_sync._typing import *
|
|
10
|
+
import functools
|
|
11
|
+
import logging
|
|
12
|
+
import weakref
|
|
13
|
+
from _typeshed import Incomplete
|
|
14
|
+
from a_sync import TaskMapping as TaskMapping
|
|
15
|
+
from a_sync.a_sync._descriptor import ASyncDescriptor as ASyncDescriptor
|
|
16
|
+
from a_sync.a_sync.abstract import ASyncABC as ASyncABC
|
|
17
|
+
from a_sync.a_sync.function import (
|
|
18
|
+
ASyncFunction as ASyncFunction,
|
|
19
|
+
ASyncFunctionAsyncDefault as ASyncFunctionAsyncDefault,
|
|
20
|
+
ASyncFunctionSyncDefault as ASyncFunctionSyncDefault,
|
|
21
|
+
)
|
|
22
|
+
from typing import Any, final
|
|
23
|
+
|
|
24
|
+
METHOD_CACHE_TTL: Literal[3600]
|
|
25
|
+
logger: logging.Logger
|
|
26
|
+
|
|
27
|
+
class ASyncMethodDescriptor(ASyncDescriptor[I, P, T]):
|
|
28
|
+
"""
|
|
29
|
+
A descriptor for managing methods that can be called both synchronously and asynchronously.
|
|
30
|
+
|
|
31
|
+
This class provides the core functionality for binding methods to instances and determining
|
|
32
|
+
the execution mode ("sync" or "async") based on various conditions, such as the instance type,
|
|
33
|
+
the method\'s default setting, or specific flags passed during the method call.
|
|
34
|
+
|
|
35
|
+
The descriptor is responsible for creating an appropriate bound method when accessed,
|
|
36
|
+
which is the actual object that can be called in both synchronous and asynchronous contexts.
|
|
37
|
+
It can create different types of bound methods (`ASyncBoundMethodSyncDefault`,
|
|
38
|
+
`ASyncBoundMethodAsyncDefault`, or `ASyncBoundMethod`) based on the default mode or instance type.
|
|
39
|
+
|
|
40
|
+
If the default mode is explicitly set to "sync" or "async", it creates `ASyncBoundMethodSyncDefault`
|
|
41
|
+
or `ASyncBoundMethodAsyncDefault` respectively. If neither is set, it defaults to creating an
|
|
42
|
+
`ASyncBoundMethod`. For instances of :class:`ASyncABC`, it checks the `__a_sync_instance_should_await__`
|
|
43
|
+
attribute to decide the type of bound method to create.
|
|
44
|
+
|
|
45
|
+
It also manages cache handles for bound methods and prevents setting or deleting the descriptor.
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
>>> class MyClass:
|
|
49
|
+
... @ASyncMethodDescriptor
|
|
50
|
+
... async def my_method(self):
|
|
51
|
+
... return "Hello, World!"
|
|
52
|
+
...
|
|
53
|
+
>>> obj = MyClass()
|
|
54
|
+
>>> await obj.my_method()
|
|
55
|
+
\'Hello, World!\'
|
|
56
|
+
>>> obj.my_method(sync=True)
|
|
57
|
+
\'Hello, World!\'
|
|
58
|
+
|
|
59
|
+
See Also:
|
|
60
|
+
- :class:`ASyncBoundMethod`
|
|
61
|
+
- :class:`ASyncFunction`
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
__wrapped__: AnyFn[P, T]
|
|
65
|
+
async def __call__(self, instance: I, *args: P.args, **kwargs: P.kwargs) -> T:
|
|
66
|
+
"""
|
|
67
|
+
Asynchronously call the method.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
instance: The instance the method is bound to.
|
|
71
|
+
*args: Positional arguments.
|
|
72
|
+
**kwargs: Keyword arguments.
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
>>> descriptor = ASyncMethodDescriptor(my_async_function)
|
|
76
|
+
>>> await descriptor(instance, arg1, arg2, kwarg1=value1)
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
@overload
|
|
80
|
+
def __get__(self, instance: None, owner: Type[I]) -> Self: ...
|
|
81
|
+
@overload
|
|
82
|
+
def __get__(self, instance: I, owner: Type[I]) -> ASyncBoundMethod[I, P, T]: ...
|
|
83
|
+
def __set__(self, instance, value) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Prevent setting the descriptor.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
instance: The instance.
|
|
89
|
+
value: The value to set.
|
|
90
|
+
|
|
91
|
+
Raises:
|
|
92
|
+
RuntimeError: Always raised to prevent setting.
|
|
93
|
+
|
|
94
|
+
Examples:
|
|
95
|
+
>>> descriptor = ASyncMethodDescriptor(my_function)
|
|
96
|
+
>>> descriptor.__set__(instance, value)
|
|
97
|
+
RuntimeError: cannot set field_name, descriptor is what you get. sorry.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
def __delete__(self, instance) -> None:
|
|
101
|
+
"""
|
|
102
|
+
Prevent deleting the descriptor.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
instance: The instance.
|
|
106
|
+
|
|
107
|
+
Raises:
|
|
108
|
+
RuntimeError: Always raised to prevent deletion.
|
|
109
|
+
|
|
110
|
+
Examples:
|
|
111
|
+
>>> descriptor = ASyncMethodDescriptor(my_function)
|
|
112
|
+
>>> descriptor.__delete__(instance)
|
|
113
|
+
RuntimeError: cannot delete field_name, you're stuck with descriptor forever. sorry.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
@functools.cached_property
|
|
117
|
+
def __is_async_def__(self) -> bool:
|
|
118
|
+
"""
|
|
119
|
+
Check if the wrapped function is a coroutine function.
|
|
120
|
+
|
|
121
|
+
Examples:
|
|
122
|
+
>>> descriptor = ASyncMethodDescriptor(my_function)
|
|
123
|
+
>>> descriptor.__is_async_def__
|
|
124
|
+
True
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
@final
|
|
128
|
+
class ASyncMethodDescriptorSyncDefault(ASyncMethodDescriptor[I, P, T]):
|
|
129
|
+
"""
|
|
130
|
+
A descriptor for :class:`ASyncBoundMethodSyncDefault` objects.
|
|
131
|
+
|
|
132
|
+
This class extends :class:`ASyncMethodDescriptor` to provide a synchronous
|
|
133
|
+
default behavior for method calls. It specifically creates `ASyncBoundMethodSyncDefault`
|
|
134
|
+
instances, which are specialized versions of `ASyncBoundMethod` with synchronous default behavior.
|
|
135
|
+
|
|
136
|
+
Examples:
|
|
137
|
+
>>> class MyClass:
|
|
138
|
+
... @ASyncMethodDescriptorSyncDefault
|
|
139
|
+
... def my_method(self):
|
|
140
|
+
... return "Hello, World!"
|
|
141
|
+
...
|
|
142
|
+
>>> obj = MyClass()
|
|
143
|
+
>>> obj.my_method()
|
|
144
|
+
\'Hello, World!\'
|
|
145
|
+
>>> coro = obj.my_method(sync=False)
|
|
146
|
+
>>> coro
|
|
147
|
+
<coroutine object MyClass.my_method at 0x7fb4f5fb49c0>
|
|
148
|
+
>>> await coro
|
|
149
|
+
\'Hello, World!\'
|
|
150
|
+
|
|
151
|
+
See Also:
|
|
152
|
+
- :class:`ASyncBoundMethodSyncDefault`
|
|
153
|
+
- :class:`ASyncFunctionSyncDefault`
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
default: str
|
|
157
|
+
any: ASyncFunctionSyncDefault[Concatenate[AnyIterable[I], P], bool]
|
|
158
|
+
all: ASyncFunctionSyncDefault[Concatenate[AnyIterable[I], P], bool]
|
|
159
|
+
min: ASyncFunctionSyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
160
|
+
max: ASyncFunctionSyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
161
|
+
sum: ASyncFunctionSyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
162
|
+
@overload
|
|
163
|
+
def __get__(
|
|
164
|
+
self, instance: None, owner: Type[I] = None
|
|
165
|
+
) -> ASyncMethodDescriptorSyncDefault[I, P, T]: ...
|
|
166
|
+
@overload
|
|
167
|
+
def __get__(
|
|
168
|
+
self, instance: I, owner: Type[I] = None
|
|
169
|
+
) -> ASyncBoundMethodSyncDefault[I, P, T]: ...
|
|
170
|
+
|
|
171
|
+
@final
|
|
172
|
+
class ASyncMethodDescriptorAsyncDefault(ASyncMethodDescriptor[I, P, T]):
|
|
173
|
+
"""
|
|
174
|
+
A descriptor for asynchronous methods with an asynchronous default.
|
|
175
|
+
|
|
176
|
+
This class extends :class:`ASyncMethodDescriptor` to provide an asynchronous default
|
|
177
|
+
behavior for method calls. It specifically creates `ASyncBoundMethodAsyncDefault`
|
|
178
|
+
instances, which are specialized versions of `ASyncBoundMethod` with asynchronous default behavior.
|
|
179
|
+
|
|
180
|
+
Examples:
|
|
181
|
+
>>> class MyClass:
|
|
182
|
+
... @ASyncMethodDescriptorAsyncDefault
|
|
183
|
+
... async def my_method(self):
|
|
184
|
+
... return "Hello, World!"
|
|
185
|
+
...
|
|
186
|
+
>>> obj = MyClass()
|
|
187
|
+
>>> coro = obj.my_method()
|
|
188
|
+
>>> coro
|
|
189
|
+
<coroutine object MyClass.my_method at 0x7fb4f5fb49c0>
|
|
190
|
+
>>> await coro
|
|
191
|
+
>>> obj.my_method(sync=True)
|
|
192
|
+
\'Hello, World!\'
|
|
193
|
+
|
|
194
|
+
See Also:
|
|
195
|
+
- :class:`ASyncBoundMethodAsyncDefault`
|
|
196
|
+
- :class:`ASyncFunctionAsyncDefault`
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
default: str
|
|
200
|
+
any: ASyncFunctionAsyncDefault[Concatenate[AnyIterable[I], P], bool]
|
|
201
|
+
all: ASyncFunctionAsyncDefault[Concatenate[AnyIterable[I], P], bool]
|
|
202
|
+
min: ASyncFunctionAsyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
203
|
+
max: ASyncFunctionAsyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
204
|
+
sum: ASyncFunctionAsyncDefault[Concatenate[AnyIterable[I], P], T]
|
|
205
|
+
@overload
|
|
206
|
+
def __get__(
|
|
207
|
+
self, instance: None, owner: Type[I]
|
|
208
|
+
) -> ASyncMethodDescriptorAsyncDefault[I, P, T]: ...
|
|
209
|
+
@overload
|
|
210
|
+
def __get__(self, instance: I, owner: Type[I]) -> ASyncBoundMethodAsyncDefault[I, P, T]: ...
|
|
211
|
+
|
|
212
|
+
class ASyncBoundMethod(ASyncFunction[P, T], Generic[I, P, T]):
|
|
213
|
+
"""
|
|
214
|
+
A bound method that can be called both synchronously and asynchronously.
|
|
215
|
+
|
|
216
|
+
This class represents a method bound to an instance, which can be called
|
|
217
|
+
either synchronously or asynchronously based on various conditions. It handles
|
|
218
|
+
caching of bound methods and includes logic for determining whether to await
|
|
219
|
+
the method call based on flags or default settings.
|
|
220
|
+
|
|
221
|
+
Examples:
|
|
222
|
+
>>> class MyClass:
|
|
223
|
+
... def __init__(self, value):
|
|
224
|
+
... self.value = value
|
|
225
|
+
...
|
|
226
|
+
... @ASyncMethodDescriptor
|
|
227
|
+
... async def my_method(self):
|
|
228
|
+
... return self.value
|
|
229
|
+
...
|
|
230
|
+
>>> obj = MyClass(42)
|
|
231
|
+
>>> await obj.my_method()
|
|
232
|
+
42
|
|
233
|
+
>>> obj.my_method(sync=True)
|
|
234
|
+
42
|
|
235
|
+
|
|
236
|
+
See Also:
|
|
237
|
+
- :class:`ASyncMethodDescriptor`
|
|
238
|
+
- :class:`ASyncFunction`
|
|
239
|
+
"""
|
|
240
|
+
|
|
241
|
+
__weakself__: weakref.ref[I]
|
|
242
|
+
__wrapped__: AnyFn[Concatenate[I, P], T]
|
|
243
|
+
def __init__(
|
|
244
|
+
self,
|
|
245
|
+
instance: I,
|
|
246
|
+
unbound: AnyFn[Concatenate[I, P], T],
|
|
247
|
+
async_def: bool,
|
|
248
|
+
**modifiers: Unpack[ModifierKwargs]
|
|
249
|
+
) -> None:
|
|
250
|
+
"""
|
|
251
|
+
Initialize the bound method.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
instance: The instance to bind the method to.
|
|
255
|
+
unbound: The unbound function.
|
|
256
|
+
async_def: Whether the original function is an async def.
|
|
257
|
+
**modifiers: Additional modifiers for the function.
|
|
258
|
+
|
|
259
|
+
Examples:
|
|
260
|
+
>>> class MyClass:
|
|
261
|
+
... def __init__(self, value):
|
|
262
|
+
... self.value = value
|
|
263
|
+
...
|
|
264
|
+
... @ASyncMethodDescriptor
|
|
265
|
+
... async def my_method(self):
|
|
266
|
+
... return self.value
|
|
267
|
+
...
|
|
268
|
+
>>> obj = MyClass(42)
|
|
269
|
+
>>> bound_method = ASyncBoundMethod(obj, MyClass.my_method, True)
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
@overload
|
|
273
|
+
def __call__(self, *args: P.args, sync: Literal[True], **kwargs: P.kwargs) -> T: ...
|
|
274
|
+
@overload
|
|
275
|
+
def __call__(
|
|
276
|
+
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
|
|
277
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
278
|
+
@overload
|
|
279
|
+
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
|
|
280
|
+
@overload
|
|
281
|
+
def __call__(
|
|
282
|
+
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
|
|
283
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
284
|
+
@overload
|
|
285
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> MaybeCoro[T]: ...
|
|
286
|
+
@property
|
|
287
|
+
def __self__(self) -> I:
|
|
288
|
+
"""
|
|
289
|
+
Get the instance the method is bound to.
|
|
290
|
+
|
|
291
|
+
Raises:
|
|
292
|
+
ReferenceError: If the instance has been garbage collected.
|
|
293
|
+
|
|
294
|
+
Examples:
|
|
295
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
296
|
+
>>> bound_method.__self__
|
|
297
|
+
<MyClass instance>
|
|
298
|
+
"""
|
|
299
|
+
|
|
300
|
+
@functools.cached_property
|
|
301
|
+
def __bound_to_a_sync_instance__(self) -> bool:
|
|
302
|
+
"""
|
|
303
|
+
Check if the method is bound to an ASyncABC instance.
|
|
304
|
+
|
|
305
|
+
Examples:
|
|
306
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
307
|
+
>>> bound_method.__bound_to_a_sync_instance__
|
|
308
|
+
True
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
def map(
|
|
312
|
+
self,
|
|
313
|
+
*iterables: AnyIterable[I],
|
|
314
|
+
concurrency: Optional[int] = None,
|
|
315
|
+
task_name: str = "",
|
|
316
|
+
**kwargs: P.kwargs
|
|
317
|
+
) -> TaskMapping[I, T]:
|
|
318
|
+
"""
|
|
319
|
+
Create a TaskMapping for this method.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
*iterables: Iterables to map over.
|
|
323
|
+
concurrency: Optional concurrency limit.
|
|
324
|
+
task_name: Optional name for the task.
|
|
325
|
+
**kwargs: Additional keyword arguments.
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
A TaskMapping instance for this method.
|
|
329
|
+
|
|
330
|
+
Examples:
|
|
331
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
332
|
+
>>> task_mapping = bound_method.map(iterable1, iterable2, concurrency=5)
|
|
333
|
+
TODO briefly include how someone would then use task_mapping
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
async def any(
|
|
337
|
+
self,
|
|
338
|
+
*iterables: AnyIterable[I],
|
|
339
|
+
concurrency: Optional[int] = None,
|
|
340
|
+
task_name: str = "",
|
|
341
|
+
**kwargs: P.kwargs
|
|
342
|
+
) -> bool:
|
|
343
|
+
"""
|
|
344
|
+
Check if any of the results are truthy.
|
|
345
|
+
|
|
346
|
+
Args:
|
|
347
|
+
*iterables: Iterables to map over.
|
|
348
|
+
concurrency: Optional concurrency limit.
|
|
349
|
+
task_name: Optional name for the task.
|
|
350
|
+
**kwargs: Additional keyword arguments.
|
|
351
|
+
|
|
352
|
+
Examples:
|
|
353
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
354
|
+
>>> result = await bound_method.any(iterable1, iterable2)
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
async def all(
|
|
358
|
+
self,
|
|
359
|
+
*iterables: AnyIterable[I],
|
|
360
|
+
concurrency: Optional[int] = None,
|
|
361
|
+
task_name: str = "",
|
|
362
|
+
**kwargs: P.kwargs
|
|
363
|
+
) -> bool:
|
|
364
|
+
"""
|
|
365
|
+
Check if all of the results are truthy.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
*iterables: Iterables to map over.
|
|
369
|
+
concurrency: Optional concurrency limit.
|
|
370
|
+
task_name: Optional name for the task.
|
|
371
|
+
**kwargs: Additional keyword arguments.
|
|
372
|
+
|
|
373
|
+
Examples:
|
|
374
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
375
|
+
>>> result = await bound_method.all(iterable1, iterable2)
|
|
376
|
+
"""
|
|
377
|
+
|
|
378
|
+
async def min(
|
|
379
|
+
self,
|
|
380
|
+
*iterables: AnyIterable[I],
|
|
381
|
+
concurrency: Optional[int] = None,
|
|
382
|
+
task_name: str = "",
|
|
383
|
+
**kwargs: P.kwargs
|
|
384
|
+
) -> T:
|
|
385
|
+
"""
|
|
386
|
+
Find the minimum result.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
*iterables: Iterables to map over.
|
|
390
|
+
concurrency: Optional concurrency limit.
|
|
391
|
+
task_name: Optional name for the task.
|
|
392
|
+
**kwargs: Additional keyword arguments.
|
|
393
|
+
|
|
394
|
+
Examples:
|
|
395
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
396
|
+
>>> result = await bound_method.min(iterable1, iterable2)
|
|
397
|
+
"""
|
|
398
|
+
|
|
399
|
+
async def max(
|
|
400
|
+
self,
|
|
401
|
+
*iterables: AnyIterable[I],
|
|
402
|
+
concurrency: Optional[int] = None,
|
|
403
|
+
task_name: str = "",
|
|
404
|
+
**kwargs: P.kwargs
|
|
405
|
+
) -> T:
|
|
406
|
+
"""
|
|
407
|
+
Find the maximum result.
|
|
408
|
+
|
|
409
|
+
Args:
|
|
410
|
+
*iterables: Iterables to map over.
|
|
411
|
+
concurrency: Optional concurrency limit.
|
|
412
|
+
task_name: Optional name for the task.
|
|
413
|
+
**kwargs: Additional keyword arguments.
|
|
414
|
+
|
|
415
|
+
Examples:
|
|
416
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
417
|
+
>>> result = await bound_method.max(iterable1, iterable2)
|
|
418
|
+
"""
|
|
419
|
+
|
|
420
|
+
async def sum(
|
|
421
|
+
self,
|
|
422
|
+
*iterables: AnyIterable[I],
|
|
423
|
+
concurrency: Optional[int] = None,
|
|
424
|
+
task_name: str = "",
|
|
425
|
+
**kwargs: P.kwargs
|
|
426
|
+
) -> T:
|
|
427
|
+
"""
|
|
428
|
+
Calculate the sum of the results.
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
*iterables: Iterables to map over.
|
|
432
|
+
concurrency: Optional concurrency limit.
|
|
433
|
+
task_name: Optional name for the task.
|
|
434
|
+
**kwargs: Additional keyword arguments.
|
|
435
|
+
|
|
436
|
+
Examples:
|
|
437
|
+
>>> bound_method = ASyncBoundMethod(instance, my_function, True)
|
|
438
|
+
>>> result = await bound_method.sum(iterable1, iterable2)
|
|
439
|
+
"""
|
|
440
|
+
|
|
441
|
+
class ASyncBoundMethodSyncDefault(ASyncBoundMethod[I, P, T]):
|
|
442
|
+
"""
|
|
443
|
+
A bound method with synchronous default behavior.
|
|
444
|
+
|
|
445
|
+
This class is a specialized version of :class:`ASyncBoundMethod` that defaults to synchronous execution.
|
|
446
|
+
It overrides the `__call__` method to enforce synchronous default behavior.
|
|
447
|
+
|
|
448
|
+
Examples:
|
|
449
|
+
>>> class MyClass:
|
|
450
|
+
... def __init__(self, value):
|
|
451
|
+
... self.value = value
|
|
452
|
+
...
|
|
453
|
+
... @ASyncMethodDescriptorSyncDefault
|
|
454
|
+
... def my_method(self):
|
|
455
|
+
... return self.value
|
|
456
|
+
...
|
|
457
|
+
>>> obj = MyClass(42)
|
|
458
|
+
>>> obj.my_method()
|
|
459
|
+
42
|
|
460
|
+
>>> await obj.my_method(sync=False)
|
|
461
|
+
42
|
|
462
|
+
|
|
463
|
+
See Also:
|
|
464
|
+
- :class:`ASyncBoundMethod`
|
|
465
|
+
- :class:`ASyncMethodDescriptorSyncDefault`
|
|
466
|
+
"""
|
|
467
|
+
|
|
468
|
+
@overload
|
|
469
|
+
def __call__(self, *args: P.args, sync: Literal[True], **kwargs: P.kwargs) -> T: ...
|
|
470
|
+
@overload
|
|
471
|
+
def __call__(
|
|
472
|
+
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
|
|
473
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
474
|
+
@overload
|
|
475
|
+
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
|
|
476
|
+
@overload
|
|
477
|
+
def __call__(
|
|
478
|
+
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
|
|
479
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
480
|
+
@overload
|
|
481
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: ...
|
|
482
|
+
__call__: Incomplete
|
|
483
|
+
|
|
484
|
+
class ASyncBoundMethodAsyncDefault(ASyncBoundMethod[I, P, T]):
|
|
485
|
+
"""
|
|
486
|
+
A bound method with asynchronous default behavior.
|
|
487
|
+
|
|
488
|
+
This class is a specialized version of :class:`ASyncBoundMethod` that defaults to asynchronous execution.
|
|
489
|
+
It overrides the `__call__` method to enforce asynchronous default behavior.
|
|
490
|
+
|
|
491
|
+
Examples:
|
|
492
|
+
>>> class MyClass:
|
|
493
|
+
... def __init__(self, value):
|
|
494
|
+
... self.value = value
|
|
495
|
+
...
|
|
496
|
+
... @ASyncMethodDescriptorAsyncDefault
|
|
497
|
+
... async def my_method(self):
|
|
498
|
+
... return self.value
|
|
499
|
+
...
|
|
500
|
+
>>> obj = MyClass(42)
|
|
501
|
+
>>> await obj.my_method()
|
|
502
|
+
42
|
|
503
|
+
>>> obj.my_method(sync=True)
|
|
504
|
+
42
|
|
505
|
+
|
|
506
|
+
See Also:
|
|
507
|
+
- :class:`ASyncBoundMethod`
|
|
508
|
+
- :class:`ASyncMethodDescriptorAsyncDefault`
|
|
509
|
+
"""
|
|
510
|
+
|
|
511
|
+
@overload
|
|
512
|
+
def __call__(self, *args: P.args, sync: Literal[True], **kwargs: P.kwargs) -> T: ...
|
|
513
|
+
@overload
|
|
514
|
+
def __call__(
|
|
515
|
+
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
|
|
516
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
517
|
+
@overload
|
|
518
|
+
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
|
|
519
|
+
@overload
|
|
520
|
+
def __call__(
|
|
521
|
+
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
|
|
522
|
+
) -> Coroutine[Any, Any, T]: ...
|
|
523
|
+
@overload
|
|
524
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Coroutine[Any, Any, T]: ...
|
|
525
|
+
__call__: Incomplete
|