ez-a-sync 0.22.15__py3-none-any.whl → 0.22.16__py3-none-any.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 +34 -3
- a_sync/__init__.py +32 -9
- a_sync/_smart.py +105 -6
- a_sync/_typing.py +56 -3
- a_sync/a_sync/_descriptor.py +174 -12
- a_sync/a_sync/_flags.py +64 -3
- a_sync/a_sync/_helpers.py +40 -8
- a_sync/a_sync/_kwargs.py +30 -6
- a_sync/a_sync/_meta.py +35 -6
- a_sync/a_sync/abstract.py +57 -9
- a_sync/a_sync/config.py +44 -7
- a_sync/a_sync/decorator.py +217 -37
- a_sync/a_sync/function.py +339 -47
- a_sync/a_sync/method.py +241 -52
- a_sync/a_sync/modifiers/__init__.py +39 -1
- a_sync/a_sync/modifiers/cache/__init__.py +75 -5
- a_sync/a_sync/modifiers/cache/memory.py +50 -6
- a_sync/a_sync/modifiers/limiter.py +55 -6
- a_sync/a_sync/modifiers/manager.py +46 -2
- a_sync/a_sync/modifiers/semaphores.py +84 -11
- a_sync/a_sync/singleton.py +43 -19
- a_sync/asyncio/__init__.py +137 -1
- a_sync/asyncio/as_completed.py +44 -38
- a_sync/asyncio/create_task.py +46 -10
- a_sync/asyncio/gather.py +72 -25
- a_sync/exceptions.py +178 -11
- a_sync/executor.py +51 -3
- a_sync/future.py +671 -29
- a_sync/iter.py +64 -7
- a_sync/primitives/_debug.py +59 -5
- a_sync/primitives/_loggable.py +36 -6
- a_sync/primitives/locks/counter.py +74 -7
- a_sync/primitives/locks/prio_semaphore.py +87 -8
- a_sync/primitives/locks/semaphore.py +68 -20
- a_sync/primitives/queue.py +65 -26
- a_sync/task.py +51 -15
- a_sync/utils/iterators.py +52 -16
- {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/METADATA +1 -1
- ez_a_sync-0.22.16.dist-info/RECORD +74 -0
- {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/WHEEL +1 -1
- tests/executor.py +150 -12
- tests/test_abstract.py +15 -0
- tests/test_base.py +198 -2
- tests/test_executor.py +23 -0
- tests/test_singleton.py +13 -1
- tests/test_task.py +45 -17
- ez_a_sync-0.22.15.dist-info/RECORD +0 -74
- {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/LICENSE.txt +0 -0
- {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/top_level.txt +0 -0
a_sync/a_sync/decorator.py
CHANGED
|
@@ -35,6 +35,20 @@ def a_sync(
|
|
|
35
35
|
Args:
|
|
36
36
|
default: Specifies the default execution mode as 'async'.
|
|
37
37
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
Basic usage with an asynchronous default:
|
|
41
|
+
|
|
42
|
+
>>> @a_sync(default='async')
|
|
43
|
+
... async def my_function():
|
|
44
|
+
... return True
|
|
45
|
+
>>> await my_function()
|
|
46
|
+
True
|
|
47
|
+
>>> my_function(sync=True)
|
|
48
|
+
True
|
|
49
|
+
|
|
50
|
+
See Also:
|
|
51
|
+
:class:`ASyncDecoratorAsyncDefault`
|
|
38
52
|
"""
|
|
39
53
|
|
|
40
54
|
|
|
@@ -49,6 +63,20 @@ def a_sync(
|
|
|
49
63
|
Args:
|
|
50
64
|
default: Specifies the default execution mode as 'sync'.
|
|
51
65
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
66
|
+
|
|
67
|
+
Examples:
|
|
68
|
+
Basic usage with a synchronous default:
|
|
69
|
+
|
|
70
|
+
>>> @a_sync(default='sync')
|
|
71
|
+
... def my_function():
|
|
72
|
+
... return True
|
|
73
|
+
>>> my_function()
|
|
74
|
+
True
|
|
75
|
+
>>> await my_function(sync=False)
|
|
76
|
+
True
|
|
77
|
+
|
|
78
|
+
See Also:
|
|
79
|
+
:class:`ASyncDecoratorSyncDefault`
|
|
52
80
|
"""
|
|
53
81
|
|
|
54
82
|
|
|
@@ -61,6 +89,20 @@ def a_sync(
|
|
|
61
89
|
|
|
62
90
|
Args:
|
|
63
91
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
Usage without specifying a default mode:
|
|
95
|
+
|
|
96
|
+
>>> @a_sync
|
|
97
|
+
... async def my_function():
|
|
98
|
+
... return True
|
|
99
|
+
>>> await my_function()
|
|
100
|
+
True
|
|
101
|
+
>>> my_function(sync=True)
|
|
102
|
+
True
|
|
103
|
+
|
|
104
|
+
See Also:
|
|
105
|
+
:class:`ASyncDecorator`
|
|
64
106
|
"""
|
|
65
107
|
|
|
66
108
|
|
|
@@ -77,6 +119,20 @@ def a_sync(
|
|
|
77
119
|
coro_fn: The coroutine function to be decorated.
|
|
78
120
|
default: Specifies no default execution mode.
|
|
79
121
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
122
|
+
|
|
123
|
+
Examples:
|
|
124
|
+
Decorating an asynchronous function without a default mode:
|
|
125
|
+
|
|
126
|
+
>>> async def my_function():
|
|
127
|
+
... return True
|
|
128
|
+
>>> decorated_function = a_sync(my_function)
|
|
129
|
+
>>> await decorated_function()
|
|
130
|
+
True
|
|
131
|
+
>>> decorated_function(sync=True)
|
|
132
|
+
True
|
|
133
|
+
|
|
134
|
+
See Also:
|
|
135
|
+
:class:`ASyncFunctionAsyncDefault`
|
|
80
136
|
"""
|
|
81
137
|
|
|
82
138
|
|
|
@@ -93,18 +149,21 @@ def a_sync(
|
|
|
93
149
|
coro_fn: The synchronous function to be decorated.
|
|
94
150
|
default: Specifies no default execution mode.
|
|
95
151
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
96
|
-
"""
|
|
97
|
-
|
|
98
152
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
153
|
+
Examples:
|
|
154
|
+
Decorating a synchronous function without a default mode:
|
|
155
|
+
|
|
156
|
+
>>> def my_function():
|
|
157
|
+
... return True
|
|
158
|
+
>>> decorated_function = a_sync(my_function)
|
|
159
|
+
>>> decorated_function()
|
|
160
|
+
True
|
|
161
|
+
>>> await decorated_function(sync=False)
|
|
162
|
+
True
|
|
163
|
+
|
|
164
|
+
See Also:
|
|
165
|
+
:class:`ASyncFunctionSyncDefault`
|
|
166
|
+
"""
|
|
108
167
|
|
|
109
168
|
|
|
110
169
|
@overload
|
|
@@ -120,6 +179,20 @@ def a_sync(
|
|
|
120
179
|
coro_fn: Specifies no function.
|
|
121
180
|
default: Specifies the default execution mode as 'async'.
|
|
122
181
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
182
|
+
|
|
183
|
+
Examples:
|
|
184
|
+
Creating an asynchronous default decorator without a function:
|
|
185
|
+
|
|
186
|
+
>>> @a_sync(default='async')
|
|
187
|
+
... async def my_function():
|
|
188
|
+
... return True
|
|
189
|
+
>>> await my_function()
|
|
190
|
+
True
|
|
191
|
+
>>> my_function(sync=True)
|
|
192
|
+
True
|
|
193
|
+
|
|
194
|
+
See Also:
|
|
195
|
+
:class:`ASyncDecoratorAsyncDefault`
|
|
123
196
|
"""
|
|
124
197
|
|
|
125
198
|
|
|
@@ -136,10 +209,21 @@ def a_sync(
|
|
|
136
209
|
coro_fn: Specifies the default execution mode as 'async'.
|
|
137
210
|
default: Specifies no default execution mode.
|
|
138
211
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
139
|
-
"""
|
|
140
|
-
|
|
141
212
|
|
|
142
|
-
|
|
213
|
+
Examples:
|
|
214
|
+
Using 'async' as the only argument:
|
|
215
|
+
|
|
216
|
+
>>> @a_sync('async')
|
|
217
|
+
... async def my_function():
|
|
218
|
+
... return True
|
|
219
|
+
>>> await my_function()
|
|
220
|
+
True
|
|
221
|
+
>>> my_function(sync=True)
|
|
222
|
+
True
|
|
223
|
+
|
|
224
|
+
See Also:
|
|
225
|
+
:class:`ASyncDecoratorAsyncDefault`
|
|
226
|
+
"""
|
|
143
227
|
|
|
144
228
|
|
|
145
229
|
@overload # async def, async default
|
|
@@ -155,6 +239,20 @@ def a_sync(
|
|
|
155
239
|
coro_fn: The coroutine function to be decorated.
|
|
156
240
|
default: Specifies the default execution mode as 'async'.
|
|
157
241
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
242
|
+
|
|
243
|
+
Examples:
|
|
244
|
+
Decorating an asynchronous function with an async default:
|
|
245
|
+
|
|
246
|
+
>>> async def my_function():
|
|
247
|
+
... return True
|
|
248
|
+
>>> decorated_function = a_sync(my_function, default='async')
|
|
249
|
+
>>> await decorated_function()
|
|
250
|
+
True
|
|
251
|
+
>>> decorated_function(sync=True)
|
|
252
|
+
True
|
|
253
|
+
|
|
254
|
+
See Also:
|
|
255
|
+
:class:`ASyncFunctionAsyncDefault`
|
|
158
256
|
"""
|
|
159
257
|
|
|
160
258
|
|
|
@@ -171,10 +269,21 @@ def a_sync(
|
|
|
171
269
|
coro_fn: The synchronous function to be decorated.
|
|
172
270
|
default: Specifies the default execution mode as 'async'.
|
|
173
271
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
174
|
-
"""
|
|
175
|
-
|
|
176
272
|
|
|
177
|
-
|
|
273
|
+
Examples:
|
|
274
|
+
Decorating a synchronous function with an async default:
|
|
275
|
+
|
|
276
|
+
>>> def my_function():
|
|
277
|
+
... return True
|
|
278
|
+
>>> decorated_function = a_sync(my_function, default='async')
|
|
279
|
+
>>> await decorated_function()
|
|
280
|
+
True
|
|
281
|
+
>>> decorated_function(sync=True)
|
|
282
|
+
True
|
|
283
|
+
|
|
284
|
+
See Also:
|
|
285
|
+
:class:`ASyncFunctionAsyncDefault`
|
|
286
|
+
"""
|
|
178
287
|
|
|
179
288
|
|
|
180
289
|
@overload # async def, sync default
|
|
@@ -190,6 +299,20 @@ def a_sync(
|
|
|
190
299
|
coro_fn: The coroutine function to be decorated.
|
|
191
300
|
default: Specifies the default execution mode as 'sync'.
|
|
192
301
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
302
|
+
|
|
303
|
+
Examples:
|
|
304
|
+
Decorating an asynchronous function with a sync default:
|
|
305
|
+
|
|
306
|
+
>>> async def my_function():
|
|
307
|
+
... return True
|
|
308
|
+
>>> decorated_function = a_sync(my_function, default='sync')
|
|
309
|
+
>>> decorated_function()
|
|
310
|
+
True
|
|
311
|
+
>>> await decorated_function(sync=False)
|
|
312
|
+
True
|
|
313
|
+
|
|
314
|
+
See Also:
|
|
315
|
+
:class:`ASyncFunctionSyncDefault`
|
|
193
316
|
"""
|
|
194
317
|
|
|
195
318
|
|
|
@@ -206,18 +329,21 @@ def a_sync(
|
|
|
206
329
|
coro_fn: The synchronous function to be decorated.
|
|
207
330
|
default: Specifies the default execution mode as 'sync'.
|
|
208
331
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
209
|
-
"""
|
|
210
332
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
333
|
+
Examples:
|
|
334
|
+
Decorating a synchronous function with a sync default:
|
|
335
|
+
|
|
336
|
+
>>> def my_function():
|
|
337
|
+
... return True
|
|
338
|
+
>>> decorated_function = a_sync(my_function, default='sync')
|
|
339
|
+
>>> decorated_function()
|
|
340
|
+
True
|
|
341
|
+
>>> await decorated_function(sync=False)
|
|
342
|
+
True
|
|
343
|
+
|
|
344
|
+
See Also:
|
|
345
|
+
:class:`ASyncFunctionSyncDefault`
|
|
346
|
+
"""
|
|
221
347
|
|
|
222
348
|
|
|
223
349
|
@overload
|
|
@@ -233,6 +359,20 @@ def a_sync(
|
|
|
233
359
|
coro_fn: Specifies no function.
|
|
234
360
|
default: Specifies the default execution mode as 'sync'.
|
|
235
361
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
362
|
+
|
|
363
|
+
Examples:
|
|
364
|
+
Creating a synchronous default decorator without a function:
|
|
365
|
+
|
|
366
|
+
>>> @a_sync(default='sync')
|
|
367
|
+
... def my_function():
|
|
368
|
+
... return True
|
|
369
|
+
>>> my_function()
|
|
370
|
+
True
|
|
371
|
+
>>> await my_function(sync=False)
|
|
372
|
+
True
|
|
373
|
+
|
|
374
|
+
See Also:
|
|
375
|
+
:class:`ASyncDecoratorSyncDefault`
|
|
236
376
|
"""
|
|
237
377
|
|
|
238
378
|
|
|
@@ -249,6 +389,20 @@ def a_sync(
|
|
|
249
389
|
coro_fn: Specifies the default execution mode as 'sync'.
|
|
250
390
|
default: Specifies no default execution mode.
|
|
251
391
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
392
|
+
|
|
393
|
+
Examples:
|
|
394
|
+
Using 'sync' as the only argument:
|
|
395
|
+
|
|
396
|
+
>>> @a_sync('sync')
|
|
397
|
+
... def my_function():
|
|
398
|
+
... return True
|
|
399
|
+
>>> my_function()
|
|
400
|
+
True
|
|
401
|
+
>>> await my_function(sync=False)
|
|
402
|
+
True
|
|
403
|
+
|
|
404
|
+
See Also:
|
|
405
|
+
:class:`ASyncDecoratorSyncDefault`
|
|
252
406
|
"""
|
|
253
407
|
|
|
254
408
|
|
|
@@ -265,6 +419,20 @@ def a_sync(
|
|
|
265
419
|
coro_fn: Specifies the default execution mode as 'sync'.
|
|
266
420
|
default: Specifies no default execution mode.
|
|
267
421
|
**modifiers: Additional keyword arguments to modify the behavior of the decorated function.
|
|
422
|
+
|
|
423
|
+
Examples:
|
|
424
|
+
Using 'sync' as the only argument:
|
|
425
|
+
|
|
426
|
+
>>> @a_sync('sync')
|
|
427
|
+
... def my_function():
|
|
428
|
+
... return True
|
|
429
|
+
>>> my_function()
|
|
430
|
+
True
|
|
431
|
+
>>> await my_function(sync=False)
|
|
432
|
+
True
|
|
433
|
+
|
|
434
|
+
See Also:
|
|
435
|
+
:class:`ASyncDecoratorSyncDefault`
|
|
268
436
|
"""
|
|
269
437
|
|
|
270
438
|
|
|
@@ -313,9 +481,9 @@ def a_sync(
|
|
|
313
481
|
>>> @a_sync
|
|
314
482
|
... async def some_async_fn():
|
|
315
483
|
... return True
|
|
316
|
-
>>> await
|
|
484
|
+
>>> await some_async_fn()
|
|
317
485
|
True
|
|
318
|
-
>>>
|
|
486
|
+
>>> some_async_fn(sync=True)
|
|
319
487
|
True
|
|
320
488
|
|
|
321
489
|
>>> @a_sync
|
|
@@ -324,7 +492,7 @@ def a_sync(
|
|
|
324
492
|
>>> some_sync_fn()
|
|
325
493
|
True
|
|
326
494
|
>>> some_sync_fn(sync=False)
|
|
327
|
-
<coroutine object some_sync_fn at
|
|
495
|
+
<coroutine object some_sync_fn at 0x7fb4f5fb49c0>
|
|
328
496
|
|
|
329
497
|
2. As a decorator with default mode specified:
|
|
330
498
|
>>> @a_sync(default='sync')
|
|
@@ -333,6 +501,17 @@ def a_sync(
|
|
|
333
501
|
...
|
|
334
502
|
>>> some_fn()
|
|
335
503
|
True
|
|
504
|
+
>>> some_fn(sync=False)
|
|
505
|
+
<coroutine object some_fn at 0x7fb4f5fb49c0>
|
|
506
|
+
|
|
507
|
+
>>> @a_sync('async')
|
|
508
|
+
... def some_fn():
|
|
509
|
+
... return True
|
|
510
|
+
...
|
|
511
|
+
>>> some_fn()
|
|
512
|
+
<coroutine object some_fn at 0x7fb4f5fb49c0>
|
|
513
|
+
>>> some_fn(asynchronous=False)
|
|
514
|
+
True
|
|
336
515
|
|
|
337
516
|
3. As a decorator with modifiers:
|
|
338
517
|
>>> @a_sync(cache_type='memory', runs_per_minute=60)
|
|
@@ -348,18 +527,19 @@ def a_sync(
|
|
|
348
527
|
"some return value"
|
|
349
528
|
|
|
350
529
|
The decorated function can then be called either synchronously or asynchronously:
|
|
351
|
-
|
|
352
|
-
result = some_fn() #
|
|
353
|
-
result = await some_fn() # Asynchronous call
|
|
530
|
+
>>> result = some_fn() # Synchronous call
|
|
531
|
+
>>> result = await some_fn() # Asynchronous call
|
|
354
532
|
|
|
355
533
|
The execution mode can also be explicitly specified during the call:
|
|
356
|
-
|
|
357
|
-
result = some_fn(sync=
|
|
358
|
-
result = await some_fn(sync=False) # Force asynchronous execution
|
|
534
|
+
>>> result = some_fn(sync=True) # Force synchronous execution
|
|
535
|
+
>>> result = await some_fn(sync=False) # Force asynchronous execution
|
|
359
536
|
|
|
360
537
|
This decorator is particularly useful for libraries that need to support
|
|
361
538
|
both synchronous and asynchronous usage, or for gradually migrating
|
|
362
539
|
synchronous code to asynchronous without breaking existing interfaces.
|
|
540
|
+
|
|
541
|
+
See Also:
|
|
542
|
+
:class:`ASyncFunction`, :class:`ASyncDecorator`
|
|
363
543
|
"""
|
|
364
544
|
|
|
365
545
|
# If the dev tried passing a default as an arg instead of a kwarg, ie: @a_sync('sync')...
|