ez-a-sync 0.32.16__cp311-cp311-macosx_11_0_arm64.whl → 0.32.18__cp311-cp311-macosx_11_0_arm64.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/_smart.cpython-311-darwin.so +0 -0
- a_sync/a_sync/_descriptor.c +4 -0
- a_sync/a_sync/_descriptor.cpython-311-darwin.so +0 -0
- a_sync/a_sync/_flags.cpython-311-darwin.so +0 -0
- a_sync/a_sync/_helpers.c +4 -0
- a_sync/a_sync/_helpers.cpython-311-darwin.so +0 -0
- a_sync/a_sync/_kwargs.cpython-311-darwin.so +0 -0
- a_sync/a_sync/_meta.py +2 -2
- a_sync/a_sync/abstract.cpython-311-darwin.so +0 -0
- a_sync/a_sync/base.cpython-311-darwin.so +0 -0
- a_sync/a_sync/flags.cpython-311-darwin.so +0 -0
- a_sync/a_sync/function.c +3494 -3054
- a_sync/a_sync/function.cpython-311-darwin.so +0 -0
- a_sync/a_sync/function.pxd +5 -1
- a_sync/a_sync/function.pyx +97 -81
- a_sync/a_sync/method.c +9838 -7638
- a_sync/a_sync/method.cpython-311-darwin.so +0 -0
- a_sync/a_sync/method.pxd +8 -1
- a_sync/a_sync/method.pyx +108 -84
- a_sync/a_sync/modifiers/manager.cpython-311-darwin.so +0 -0
- a_sync/a_sync/property.c +435 -384
- a_sync/a_sync/property.cpython-311-darwin.so +0 -0
- a_sync/a_sync/property.pyx +9 -7
- a_sync/async_property/cached.cpython-311-darwin.so +0 -0
- a_sync/async_property/proxy.cpython-311-darwin.so +0 -0
- a_sync/asyncio/as_completed.cpython-311-darwin.so +0 -0
- a_sync/asyncio/create_task.cpython-311-darwin.so +0 -0
- a_sync/asyncio/gather.cpython-311-darwin.so +0 -0
- a_sync/asyncio/igather.cpython-311-darwin.so +0 -0
- a_sync/asyncio/sleep.cpython-311-darwin.so +0 -0
- a_sync/debugging.cpython-311-darwin.so +0 -0
- a_sync/exceptions.cpython-311-darwin.so +0 -0
- a_sync/functools.cpython-311-darwin.so +0 -0
- a_sync/iter.cpython-311-darwin.so +0 -0
- a_sync/primitives/_debug.cpython-311-darwin.so +0 -0
- a_sync/primitives/_loggable.cpython-311-darwin.so +0 -0
- a_sync/primitives/locks/counter.cpython-311-darwin.so +0 -0
- a_sync/primitives/locks/event.cpython-311-darwin.so +0 -0
- a_sync/primitives/locks/prio_semaphore.cpython-311-darwin.so +0 -0
- a_sync/primitives/locks/semaphore.cpython-311-darwin.so +0 -0
- a_sync/task.py +1 -1
- a_sync/utils/repr.cpython-311-darwin.so +0 -0
- {ez_a_sync-0.32.16.dist-info → ez_a_sync-0.32.18.dist-info}/METADATA +1 -1
- {ez_a_sync-0.32.16.dist-info → ez_a_sync-0.32.18.dist-info}/RECORD +47 -47
- {ez_a_sync-0.32.16.dist-info → ez_a_sync-0.32.18.dist-info}/WHEEL +0 -0
- {ez_a_sync-0.32.16.dist-info → ez_a_sync-0.32.18.dist-info}/licenses/LICENSE.txt +0 -0
- {ez_a_sync-0.32.16.dist-info → ez_a_sync-0.32.18.dist-info}/top_level.txt +0 -0
|
Binary file
|
a_sync/a_sync/function.pxd
CHANGED
|
@@ -20,5 +20,9 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
20
20
|
cdef object __modified_fn
|
|
21
21
|
cdef object __async_wrap
|
|
22
22
|
cdef object __sync_wrap
|
|
23
|
+
cdef object get_fn(self)
|
|
24
|
+
cpdef bint is_async_def(self)
|
|
25
|
+
cpdef bint is_sync_default(self)
|
|
26
|
+
cdef inline bint _run_sync(self, dict kwargs)
|
|
23
27
|
|
|
24
|
-
cdef void _validate_wrapped_fn(object fn)
|
|
28
|
+
cdef void _validate_wrapped_fn(object fn)
|
a_sync/a_sync/function.pyx
CHANGED
|
@@ -203,29 +203,6 @@ cdef inline void _validate_argspec(fn: Callable):
|
|
|
203
203
|
f"{fn} must not have any arguments with the following names: {VIABLE_FLAGS}"
|
|
204
204
|
)
|
|
205
205
|
|
|
206
|
-
cdef inline bint _run_sync(object function, dict kwargs):
|
|
207
|
-
"""
|
|
208
|
-
Determines whether to run the function synchronously or asynchronously.
|
|
209
|
-
|
|
210
|
-
This method checks for a flag in the kwargs and defers to it if present.
|
|
211
|
-
If no flag is specified, it defers to the default execution mode.
|
|
212
|
-
|
|
213
|
-
Args:
|
|
214
|
-
kwargs: The keyword arguments passed to the function.
|
|
215
|
-
|
|
216
|
-
Returns:
|
|
217
|
-
True if the function should run synchronously, otherwise False.
|
|
218
|
-
|
|
219
|
-
See Also:
|
|
220
|
-
- :func:`_kwargs.get_flag_name`
|
|
221
|
-
"""
|
|
222
|
-
cdef str flag = get_flag_name(kwargs)
|
|
223
|
-
if flag:
|
|
224
|
-
# If a flag was specified in the kwargs, we will defer to it.
|
|
225
|
-
return is_sync(flag, kwargs, pop_flag=True)
|
|
226
|
-
else:
|
|
227
|
-
# No flag specified in the kwargs, we will defer to 'default'.
|
|
228
|
-
return function._sync_default
|
|
229
206
|
|
|
230
207
|
cdef class _ASyncFunction(_ModifiedMixin):
|
|
231
208
|
"""
|
|
@@ -317,10 +294,11 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
317
294
|
- :attr:`default`
|
|
318
295
|
- :meth:`_run_sync`
|
|
319
296
|
"""
|
|
297
|
+
fn = self.get_fn()
|
|
320
298
|
_logger_debug(
|
|
321
|
-
"calling %s fn: %s with args: %s kwargs: %s", self,
|
|
299
|
+
"calling %s fn: %s with args: %s kwargs: %s", self, fn, args, kwargs
|
|
322
300
|
)
|
|
323
|
-
return
|
|
301
|
+
return fn(*args, **kwargs)
|
|
324
302
|
|
|
325
303
|
def __repr__(self) -> str:
|
|
326
304
|
return "<{} {}.{} at {}>".format(
|
|
@@ -341,9 +319,12 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
341
319
|
- :meth:`_async_wrap`
|
|
342
320
|
- :meth:`_sync_wrap`
|
|
343
321
|
"""
|
|
322
|
+
return self.get_fn()
|
|
323
|
+
|
|
324
|
+
cdef object get_fn(self):
|
|
344
325
|
fn = self._fn
|
|
345
326
|
if fn is None:
|
|
346
|
-
fn = self._async_wrap if self.
|
|
327
|
+
fn = self._async_wrap if self.is_async_def() else self._sync_wrap
|
|
347
328
|
self._fn = fn
|
|
348
329
|
return fn
|
|
349
330
|
|
|
@@ -707,51 +688,6 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
707
688
|
**function_kwargs,
|
|
708
689
|
).sum(pop=True, sync=False)
|
|
709
690
|
|
|
710
|
-
@property
|
|
711
|
-
def _sync_default(self) -> bint:
|
|
712
|
-
"""
|
|
713
|
-
Determines the default execution mode (sync or async) for the function.
|
|
714
|
-
|
|
715
|
-
If the user did not specify a default, this method defers to the function's
|
|
716
|
-
definition (sync vs async def).
|
|
717
|
-
|
|
718
|
-
Returns:
|
|
719
|
-
True if the default is sync, False if async.
|
|
720
|
-
|
|
721
|
-
See Also:
|
|
722
|
-
- :attr:`default`
|
|
723
|
-
"""
|
|
724
|
-
if self.__sync_default_cached:
|
|
725
|
-
return self.__sync_default
|
|
726
|
-
|
|
727
|
-
cdef str default = self.get_default()
|
|
728
|
-
cdef bint sync_default = (
|
|
729
|
-
True
|
|
730
|
-
if default == "sync"
|
|
731
|
-
else False if default == "async" else not self._async_def
|
|
732
|
-
)
|
|
733
|
-
self.__sync_default = sync_default
|
|
734
|
-
self.__sync_default_cached = True
|
|
735
|
-
return sync_default
|
|
736
|
-
|
|
737
|
-
@property
|
|
738
|
-
def _async_def(self) -> bint:
|
|
739
|
-
"""
|
|
740
|
-
Checks if the wrapped function is an asynchronous function.
|
|
741
|
-
|
|
742
|
-
Returns:
|
|
743
|
-
True if the function is asynchronous, otherwise False.
|
|
744
|
-
|
|
745
|
-
See Also:
|
|
746
|
-
- :func:`asyncio.iscoroutinefunction`
|
|
747
|
-
"""
|
|
748
|
-
if self.__async_def_cached:
|
|
749
|
-
return self.__async_def
|
|
750
|
-
cdef bint async_def
|
|
751
|
-
async_def = self.__async_def = iscoroutinefunction(self.__wrapped__)
|
|
752
|
-
self.__async_def_cached = True
|
|
753
|
-
return async_def
|
|
754
|
-
|
|
755
691
|
@property
|
|
756
692
|
def _asyncified(self) -> CoroFn[P, T]:
|
|
757
693
|
"""
|
|
@@ -768,7 +704,7 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
768
704
|
"""
|
|
769
705
|
asyncified = self.__asyncified
|
|
770
706
|
if asyncified is None:
|
|
771
|
-
if self.
|
|
707
|
+
if self.is_async_def():
|
|
772
708
|
raise TypeError(
|
|
773
709
|
f"Can only be applied to sync functions, not {self.__wrapped__}"
|
|
774
710
|
)
|
|
@@ -793,10 +729,17 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
793
729
|
"""
|
|
794
730
|
modified_fn = self.__modified_fn
|
|
795
731
|
if modified_fn is None:
|
|
796
|
-
|
|
797
|
-
|
|
732
|
+
|
|
733
|
+
# recursively unwrap ASync objects to get to the original wrapped callable
|
|
734
|
+
wrapped = self.__wrapped__
|
|
735
|
+
while isinstance(wrapped, _ASyncFunction):
|
|
736
|
+
wrapped = wrapped.__wrapped__
|
|
737
|
+
|
|
738
|
+
if self.is_async_def():
|
|
739
|
+
modified_fn = self.__modified_fn = self.modifiers.apply_async_modifiers(wrapped)
|
|
798
740
|
else:
|
|
799
|
-
modified_fn = self.__modified_fn = self.modifiers.apply_sync_modifiers(
|
|
741
|
+
modified_fn = self.__modified_fn = self.modifiers.apply_sync_modifiers(wrapped)
|
|
742
|
+
|
|
800
743
|
return modified_fn
|
|
801
744
|
|
|
802
745
|
@property
|
|
@@ -825,7 +768,7 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
825
768
|
# we dont want this so profiler outputs are more useful
|
|
826
769
|
|
|
827
770
|
# Must take place before coro is created, we're popping a kwarg.
|
|
828
|
-
should_await = _run_sync(
|
|
771
|
+
should_await = self._run_sync(kwargs)
|
|
829
772
|
coro = modified_fn(*args, **kwargs)
|
|
830
773
|
if should_await:
|
|
831
774
|
return await_helper(coro)
|
|
@@ -858,7 +801,7 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
858
801
|
|
|
859
802
|
@wraps(modified_fn)
|
|
860
803
|
def sync_wrap(*args: P.args, **kwargs: P.kwargs) -> MaybeAwaitable[T]: # type: ignore [name-defined]
|
|
861
|
-
if _run_sync(
|
|
804
|
+
if self._run_sync(kwargs):
|
|
862
805
|
return modified_fn(*args, **kwargs)
|
|
863
806
|
return asyncified(*args, **kwargs)
|
|
864
807
|
|
|
@@ -866,6 +809,79 @@ cdef class _ASyncFunction(_ModifiedMixin):
|
|
|
866
809
|
|
|
867
810
|
return sync_wrap
|
|
868
811
|
|
|
812
|
+
cpdef bint is_async_def(self):
|
|
813
|
+
"""
|
|
814
|
+
Checks if the wrapped function is an asynchronous function.
|
|
815
|
+
|
|
816
|
+
Returns:
|
|
817
|
+
True if the function is asynchronous, otherwise False.
|
|
818
|
+
|
|
819
|
+
See Also:
|
|
820
|
+
- :func:`asyncio.iscoroutinefunction`
|
|
821
|
+
"""
|
|
822
|
+
if self.__async_def_cached:
|
|
823
|
+
return self.__async_def
|
|
824
|
+
cdef bint async_def
|
|
825
|
+
|
|
826
|
+
# recursively unwrap ASync callables to get the original wrapped fn
|
|
827
|
+
wrapped = self.__wrapped__
|
|
828
|
+
while isinstance(wrapped, _ASyncFunction):
|
|
829
|
+
wrapped = wrapped.__wrapped__
|
|
830
|
+
|
|
831
|
+
async_def = self.__async_def = iscoroutinefunction(wrapped)
|
|
832
|
+
self.__async_def_cached = True
|
|
833
|
+
return async_def
|
|
834
|
+
|
|
835
|
+
cpdef bint is_sync_default(self):
|
|
836
|
+
"""
|
|
837
|
+
Determines the default execution mode (sync or async) for the function.
|
|
838
|
+
|
|
839
|
+
If the user did not specify a default, this method defers to the function's
|
|
840
|
+
definition (sync vs async def).
|
|
841
|
+
|
|
842
|
+
Returns:
|
|
843
|
+
True if the default is sync, False if async.
|
|
844
|
+
|
|
845
|
+
See Also:
|
|
846
|
+
- :attr:`default`
|
|
847
|
+
"""
|
|
848
|
+
if self.__sync_default_cached:
|
|
849
|
+
return self.__sync_default
|
|
850
|
+
|
|
851
|
+
cdef str default = self.get_default()
|
|
852
|
+
cdef bint sync_default = (
|
|
853
|
+
True
|
|
854
|
+
if default == "sync"
|
|
855
|
+
else False if default == "async" else not self.is_async_def()
|
|
856
|
+
)
|
|
857
|
+
self.__sync_default = sync_default
|
|
858
|
+
self.__sync_default_cached = True
|
|
859
|
+
return sync_default
|
|
860
|
+
|
|
861
|
+
cdef inline bint _run_sync(self, dict kwargs):
|
|
862
|
+
"""
|
|
863
|
+
Determines whether to run the function synchronously or asynchronously.
|
|
864
|
+
|
|
865
|
+
This method checks for a flag in the kwargs and defers to it if present.
|
|
866
|
+
If no flag is specified, it defers to the default execution mode.
|
|
867
|
+
|
|
868
|
+
Args:
|
|
869
|
+
kwargs: The keyword arguments passed to the function.
|
|
870
|
+
|
|
871
|
+
Returns:
|
|
872
|
+
True if the function should run synchronously, otherwise False.
|
|
873
|
+
|
|
874
|
+
See Also:
|
|
875
|
+
- :func:`_kwargs.get_flag_name`
|
|
876
|
+
"""
|
|
877
|
+
cdef str flag = get_flag_name(kwargs)
|
|
878
|
+
if flag:
|
|
879
|
+
# If a flag was specified in the kwargs, we will defer to it.
|
|
880
|
+
return is_sync(flag, kwargs, pop_flag=True)
|
|
881
|
+
else:
|
|
882
|
+
# No flag specified in the kwargs, we will defer to 'default'.
|
|
883
|
+
return self.is_sync_default()
|
|
884
|
+
|
|
869
885
|
|
|
870
886
|
class ASyncFunction(_ASyncFunction, Generic[P, T]):
|
|
871
887
|
|
|
@@ -1157,7 +1173,7 @@ class ASyncFunctionSyncDefault(ASyncFunction[P, T]):
|
|
|
1157
1173
|
# TODO write specific docs for this overload
|
|
1158
1174
|
...
|
|
1159
1175
|
|
|
1160
|
-
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> MaybeCoro[T]:
|
|
1176
|
+
def __call__(_ASyncFunction self, *args: P.args, **kwargs: P.kwargs) -> MaybeCoro[T]:
|
|
1161
1177
|
"""Calls the wrapped function, defaulting to synchronous execution.
|
|
1162
1178
|
|
|
1163
1179
|
This method overrides the base :meth:`ASyncFunction.__call__` to provide a synchronous
|
|
@@ -1176,7 +1192,7 @@ class ASyncFunctionSyncDefault(ASyncFunction[P, T]):
|
|
|
1176
1192
|
See Also:
|
|
1177
1193
|
- :meth:`ASyncFunction.__call__`
|
|
1178
1194
|
"""
|
|
1179
|
-
return self.
|
|
1195
|
+
return self.get_fn()(*args, **kwargs)
|
|
1180
1196
|
|
|
1181
1197
|
__docstring_append__ = ":class:`~a_sync.a_sync.function.ASyncFunctionSyncDefault`, you can optionally pass `sync=False` or `asynchronous=True` to force it to return a coroutine. Without either kwarg, it will run synchronously."
|
|
1182
1198
|
|
|
@@ -1232,7 +1248,7 @@ class ASyncFunctionAsyncDefault(ASyncFunction[P, T]):
|
|
|
1232
1248
|
|
|
1233
1249
|
@overload
|
|
1234
1250
|
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Coroutine[Any, Any, T]: ...
|
|
1235
|
-
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> MaybeCoro[T]:
|
|
1251
|
+
def __call__(_ASyncFunction self, *args: P.args, **kwargs: P.kwargs) -> MaybeCoro[T]:
|
|
1236
1252
|
"""Calls the wrapped function, defaulting to asynchronous execution.
|
|
1237
1253
|
|
|
1238
1254
|
This method overrides the base :meth:`ASyncFunction.__call__` to provide an asynchronous
|
|
@@ -1251,7 +1267,7 @@ class ASyncFunctionAsyncDefault(ASyncFunction[P, T]):
|
|
|
1251
1267
|
See Also:
|
|
1252
1268
|
- :meth:`ASyncFunction.__call__`
|
|
1253
1269
|
"""
|
|
1254
|
-
return self.
|
|
1270
|
+
return self.get_fn()(*args, **kwargs)
|
|
1255
1271
|
|
|
1256
1272
|
__docstring_append__ = ":class:`~a_sync.a_sync.function.ASyncFunctionAsyncDefault`, you can optionally pass `sync=True` or `asynchronous=False` to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await."
|
|
1257
1273
|
|