ez-a-sync 0.32.9__cp310-cp310-musllinux_1_2_i686.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.

Files changed (177) hide show
  1. a_sync/ENVIRONMENT_VARIABLES.py +42 -0
  2. a_sync/__init__.pxd +2 -0
  3. a_sync/__init__.py +144 -0
  4. a_sync/_smart.c +22623 -0
  5. a_sync/_smart.cpython-310-i386-linux-gnu.so +0 -0
  6. a_sync/_smart.pxd +2 -0
  7. a_sync/_smart.pyi +202 -0
  8. a_sync/_smart.pyx +652 -0
  9. a_sync/_typing.py +258 -0
  10. a_sync/a_sync/__init__.py +60 -0
  11. a_sync/a_sync/_descriptor.c +19745 -0
  12. a_sync/a_sync/_descriptor.cpython-310-i386-linux-gnu.so +0 -0
  13. a_sync/a_sync/_descriptor.pyi +34 -0
  14. a_sync/a_sync/_descriptor.pyx +422 -0
  15. a_sync/a_sync/_flags.c +5687 -0
  16. a_sync/a_sync/_flags.cpython-310-i386-linux-gnu.so +0 -0
  17. a_sync/a_sync/_flags.pxd +3 -0
  18. a_sync/a_sync/_flags.pyx +92 -0
  19. a_sync/a_sync/_helpers.c +13718 -0
  20. a_sync/a_sync/_helpers.cpython-310-i386-linux-gnu.so +0 -0
  21. a_sync/a_sync/_helpers.pxd +3 -0
  22. a_sync/a_sync/_helpers.pyi +10 -0
  23. a_sync/a_sync/_helpers.pyx +167 -0
  24. a_sync/a_sync/_kwargs.c +10672 -0
  25. a_sync/a_sync/_kwargs.cpython-310-i386-linux-gnu.so +0 -0
  26. a_sync/a_sync/_kwargs.pxd +2 -0
  27. a_sync/a_sync/_kwargs.pyx +64 -0
  28. a_sync/a_sync/_meta.py +210 -0
  29. a_sync/a_sync/abstract.c +11350 -0
  30. a_sync/a_sync/abstract.cpython-310-i386-linux-gnu.so +0 -0
  31. a_sync/a_sync/abstract.pyi +141 -0
  32. a_sync/a_sync/abstract.pyx +221 -0
  33. a_sync/a_sync/base.c +14066 -0
  34. a_sync/a_sync/base.cpython-310-i386-linux-gnu.so +0 -0
  35. a_sync/a_sync/base.pyi +60 -0
  36. a_sync/a_sync/base.pyx +271 -0
  37. a_sync/a_sync/config.py +168 -0
  38. a_sync/a_sync/decorator.py +562 -0
  39. a_sync/a_sync/flags.c +4471 -0
  40. a_sync/a_sync/flags.cpython-310-i386-linux-gnu.so +0 -0
  41. a_sync/a_sync/flags.pxd +72 -0
  42. a_sync/a_sync/flags.pyi +74 -0
  43. a_sync/a_sync/flags.pyx +72 -0
  44. a_sync/a_sync/function.c +37747 -0
  45. a_sync/a_sync/function.cpython-310-i386-linux-gnu.so +0 -0
  46. a_sync/a_sync/function.pxd +24 -0
  47. a_sync/a_sync/function.pyi +556 -0
  48. a_sync/a_sync/function.pyx +1363 -0
  49. a_sync/a_sync/method.c +28387 -0
  50. a_sync/a_sync/method.cpython-310-i386-linux-gnu.so +0 -0
  51. a_sync/a_sync/method.pxd +2 -0
  52. a_sync/a_sync/method.pyi +524 -0
  53. a_sync/a_sync/method.pyx +999 -0
  54. a_sync/a_sync/modifiers/__init__.pxd +1 -0
  55. a_sync/a_sync/modifiers/__init__.py +101 -0
  56. a_sync/a_sync/modifiers/cache/__init__.py +160 -0
  57. a_sync/a_sync/modifiers/cache/memory.py +165 -0
  58. a_sync/a_sync/modifiers/limiter.py +132 -0
  59. a_sync/a_sync/modifiers/manager.c +15262 -0
  60. a_sync/a_sync/modifiers/manager.cpython-310-i386-linux-gnu.so +0 -0
  61. a_sync/a_sync/modifiers/manager.pxd +5 -0
  62. a_sync/a_sync/modifiers/manager.pyi +219 -0
  63. a_sync/a_sync/modifiers/manager.pyx +296 -0
  64. a_sync/a_sync/modifiers/semaphores.py +173 -0
  65. a_sync/a_sync/property.c +27952 -0
  66. a_sync/a_sync/property.cpython-310-i386-linux-gnu.so +0 -0
  67. a_sync/a_sync/property.pyi +376 -0
  68. a_sync/a_sync/property.pyx +813 -0
  69. a_sync/a_sync/singleton.py +63 -0
  70. a_sync/aliases.py +3 -0
  71. a_sync/async_property/__init__.pxd +1 -0
  72. a_sync/async_property/__init__.py +1 -0
  73. a_sync/async_property/cached.c +20542 -0
  74. a_sync/async_property/cached.cpython-310-i386-linux-gnu.so +0 -0
  75. a_sync/async_property/cached.pxd +10 -0
  76. a_sync/async_property/cached.pyi +45 -0
  77. a_sync/async_property/cached.pyx +178 -0
  78. a_sync/async_property/proxy.c +36410 -0
  79. a_sync/async_property/proxy.cpython-310-i386-linux-gnu.so +0 -0
  80. a_sync/async_property/proxy.pxd +2 -0
  81. a_sync/async_property/proxy.pyi +124 -0
  82. a_sync/async_property/proxy.pyx +474 -0
  83. a_sync/asyncio/__init__.pxd +6 -0
  84. a_sync/asyncio/__init__.py +164 -0
  85. a_sync/asyncio/as_completed.c +18198 -0
  86. a_sync/asyncio/as_completed.cpython-310-i386-linux-gnu.so +0 -0
  87. a_sync/asyncio/as_completed.pxd +8 -0
  88. a_sync/asyncio/as_completed.pyi +109 -0
  89. a_sync/asyncio/as_completed.pyx +269 -0
  90. a_sync/asyncio/create_task.c +15032 -0
  91. a_sync/asyncio/create_task.cpython-310-i386-linux-gnu.so +0 -0
  92. a_sync/asyncio/create_task.pxd +2 -0
  93. a_sync/asyncio/create_task.pyi +51 -0
  94. a_sync/asyncio/create_task.pyx +268 -0
  95. a_sync/asyncio/gather.c +15735 -0
  96. a_sync/asyncio/gather.cpython-310-i386-linux-gnu.so +0 -0
  97. a_sync/asyncio/gather.pyi +107 -0
  98. a_sync/asyncio/gather.pyx +218 -0
  99. a_sync/asyncio/igather.c +12334 -0
  100. a_sync/asyncio/igather.cpython-310-i386-linux-gnu.so +0 -0
  101. a_sync/asyncio/igather.pxd +1 -0
  102. a_sync/asyncio/igather.pyi +7 -0
  103. a_sync/asyncio/igather.pyx +175 -0
  104. a_sync/asyncio/sleep.c +8916 -0
  105. a_sync/asyncio/sleep.cpython-310-i386-linux-gnu.so +0 -0
  106. a_sync/asyncio/sleep.pyi +14 -0
  107. a_sync/asyncio/sleep.pyx +49 -0
  108. a_sync/debugging.c +15156 -0
  109. a_sync/debugging.cpython-310-i386-linux-gnu.so +0 -0
  110. a_sync/debugging.pyi +73 -0
  111. a_sync/debugging.pyx +107 -0
  112. a_sync/exceptions.c +12952 -0
  113. a_sync/exceptions.cpython-310-i386-linux-gnu.so +0 -0
  114. a_sync/exceptions.pyi +376 -0
  115. a_sync/exceptions.pyx +443 -0
  116. a_sync/executor.py +575 -0
  117. a_sync/functools.c +11489 -0
  118. a_sync/functools.cpython-310-i386-linux-gnu.so +0 -0
  119. a_sync/functools.pxd +7 -0
  120. a_sync/functools.pyi +33 -0
  121. a_sync/functools.pyx +139 -0
  122. a_sync/future.py +1497 -0
  123. a_sync/iter.c +37567 -0
  124. a_sync/iter.cpython-310-i386-linux-gnu.so +0 -0
  125. a_sync/iter.pxd +9 -0
  126. a_sync/iter.pyi +366 -0
  127. a_sync/iter.pyx +981 -0
  128. a_sync/primitives/__init__.pxd +1 -0
  129. a_sync/primitives/__init__.py +53 -0
  130. a_sync/primitives/_debug.c +14737 -0
  131. a_sync/primitives/_debug.cpython-310-i386-linux-gnu.so +0 -0
  132. a_sync/primitives/_debug.pxd +12 -0
  133. a_sync/primitives/_debug.pyi +52 -0
  134. a_sync/primitives/_debug.pyx +223 -0
  135. a_sync/primitives/_loggable.c +10569 -0
  136. a_sync/primitives/_loggable.cpython-310-i386-linux-gnu.so +0 -0
  137. a_sync/primitives/_loggable.pxd +4 -0
  138. a_sync/primitives/_loggable.pyi +66 -0
  139. a_sync/primitives/_loggable.pyx +102 -0
  140. a_sync/primitives/locks/__init__.pxd +8 -0
  141. a_sync/primitives/locks/__init__.py +17 -0
  142. a_sync/primitives/locks/counter.c +16972 -0
  143. a_sync/primitives/locks/counter.cpython-310-i386-linux-gnu.so +0 -0
  144. a_sync/primitives/locks/counter.pxd +12 -0
  145. a_sync/primitives/locks/counter.pyi +151 -0
  146. a_sync/primitives/locks/counter.pyx +260 -0
  147. a_sync/primitives/locks/event.c +16127 -0
  148. a_sync/primitives/locks/event.cpython-310-i386-linux-gnu.so +0 -0
  149. a_sync/primitives/locks/event.pxd +22 -0
  150. a_sync/primitives/locks/event.pyi +43 -0
  151. a_sync/primitives/locks/event.pyx +183 -0
  152. a_sync/primitives/locks/prio_semaphore.c +24084 -0
  153. a_sync/primitives/locks/prio_semaphore.cpython-310-i386-linux-gnu.so +0 -0
  154. a_sync/primitives/locks/prio_semaphore.pxd +24 -0
  155. a_sync/primitives/locks/prio_semaphore.pyi +217 -0
  156. a_sync/primitives/locks/prio_semaphore.pyx +554 -0
  157. a_sync/primitives/locks/semaphore.c +25816 -0
  158. a_sync/primitives/locks/semaphore.cpython-310-i386-linux-gnu.so +0 -0
  159. a_sync/primitives/locks/semaphore.pxd +21 -0
  160. a_sync/primitives/locks/semaphore.pyi +196 -0
  161. a_sync/primitives/locks/semaphore.pyx +452 -0
  162. a_sync/primitives/queue.py +1018 -0
  163. a_sync/py.typed +0 -0
  164. a_sync/sphinx/__init__.py +3 -0
  165. a_sync/sphinx/ext.py +289 -0
  166. a_sync/task.py +916 -0
  167. a_sync/utils/__init__.py +105 -0
  168. a_sync/utils/iterators.py +297 -0
  169. a_sync/utils/repr.c +14354 -0
  170. a_sync/utils/repr.cpython-310-i386-linux-gnu.so +0 -0
  171. a_sync/utils/repr.pyi +2 -0
  172. a_sync/utils/repr.pyx +73 -0
  173. ez_a_sync-0.32.9.dist-info/METADATA +367 -0
  174. ez_a_sync-0.32.9.dist-info/RECORD +177 -0
  175. ez_a_sync-0.32.9.dist-info/WHEEL +5 -0
  176. ez_a_sync-0.32.9.dist-info/licenses/LICENSE.txt +17 -0
  177. ez_a_sync-0.32.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,562 @@
1
+ # mypy: disable-error-code=valid-type
2
+ # mypy: disable-error-code=misc
3
+ from a_sync._typing import *
4
+ from a_sync.a_sync import config
5
+ from a_sync.a_sync.function import (
6
+ ASyncDecorator,
7
+ ASyncFunction,
8
+ ASyncDecoratorAsyncDefault,
9
+ ASyncDecoratorSyncDefault,
10
+ ASyncFunctionAsyncDefault,
11
+ ASyncFunctionSyncDefault,
12
+ )
13
+
14
+ ########################
15
+ # The a_sync decorator #
16
+ ########################
17
+
18
+ # @a_sync
19
+ # def some_fn():
20
+ # pass
21
+ #
22
+ # @a_sync
23
+ # async def some_fn():
24
+ # pass
25
+
26
+
27
+ @overload
28
+ def a_sync(
29
+ default: Literal["async"],
30
+ **modifiers: Unpack[ModifierKwargs],
31
+ ) -> ASyncDecoratorAsyncDefault:
32
+ """
33
+ Creates an asynchronous default decorator.
34
+
35
+ Args:
36
+ default: Specifies the default execution mode as 'async'.
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`
52
+ """
53
+
54
+
55
+ @overload
56
+ def a_sync(
57
+ default: Literal["sync"],
58
+ **modifiers: Unpack[ModifierKwargs],
59
+ ) -> ASyncDecoratorSyncDefault:
60
+ """
61
+ Creates a synchronous default decorator.
62
+
63
+ Args:
64
+ default: Specifies the default execution mode as 'sync'.
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`
80
+ """
81
+
82
+
83
+ @overload
84
+ def a_sync(
85
+ **modifiers: Unpack[ModifierKwargs],
86
+ ) -> ASyncDecorator:
87
+ """
88
+ Creates a decorator with no default execution mode specified.
89
+
90
+ Args:
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`
106
+ """
107
+
108
+
109
+ @overload # async def, None default
110
+ def a_sync(
111
+ coro_fn: CoroFn[P, T],
112
+ default: Literal[None] = None,
113
+ **modifiers: Unpack[ModifierKwargs],
114
+ ) -> "ASyncFunctionAsyncDefault[P, T]":
115
+ """
116
+ Decorates an asynchronous function with no default execution mode specified.
117
+
118
+ Args:
119
+ coro_fn: The coroutine function to be decorated.
120
+ default: Specifies no default execution mode.
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`
136
+ """
137
+
138
+
139
+ @overload # sync def none default
140
+ def a_sync(
141
+ coro_fn: SyncFn[P, T],
142
+ default: Literal[None] = None,
143
+ **modifiers: Unpack[ModifierKwargs],
144
+ ) -> "ASyncFunctionSyncDefault[P, T]":
145
+ """
146
+ Decorates a synchronous function with no default execution mode specified.
147
+
148
+ Args:
149
+ coro_fn: The synchronous function to be decorated.
150
+ default: Specifies no default execution mode.
151
+ **modifiers: Additional keyword arguments to modify the behavior of the decorated function.
152
+
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
+ """
167
+
168
+
169
+ @overload
170
+ def a_sync(
171
+ coro_fn: Literal[None],
172
+ default: Literal["async"],
173
+ **modifiers: Unpack[ModifierKwargs],
174
+ ) -> ASyncDecoratorAsyncDefault:
175
+ """
176
+ Creates an asynchronous default decorator with no function specified.
177
+
178
+ Args:
179
+ coro_fn: Specifies no function.
180
+ default: Specifies the default execution mode as 'async'.
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`
196
+ """
197
+
198
+
199
+ @overload # if you try to use default as the only arg
200
+ def a_sync(
201
+ coro_fn: Literal["async"],
202
+ default: Literal[None],
203
+ **modifiers: Unpack[ModifierKwargs],
204
+ ) -> ASyncDecoratorAsyncDefault:
205
+ """
206
+ Creates an asynchronous default decorator with no default execution mode specified.
207
+
208
+ Args:
209
+ coro_fn: Specifies the default execution mode as 'async'.
210
+ default: Specifies no default execution mode.
211
+ **modifiers: Additional keyword arguments to modify the behavior of the decorated function.
212
+
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
+ """
227
+
228
+
229
+ @overload # async def, async default
230
+ def a_sync(
231
+ coro_fn: CoroFn[P, T],
232
+ default: Literal["async"],
233
+ **modifiers: Unpack[ModifierKwargs],
234
+ ) -> "ASyncFunctionAsyncDefault[P, T]":
235
+ """
236
+ Decorates an asynchronous function with an asynchronous default execution mode.
237
+
238
+ Args:
239
+ coro_fn: The coroutine function to be decorated.
240
+ default: Specifies the default execution mode as 'async'.
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`
256
+ """
257
+
258
+
259
+ @overload # sync def async default
260
+ def a_sync(
261
+ coro_fn: SyncFn[P, T],
262
+ default: Literal["async"],
263
+ **modifiers: Unpack[ModifierKwargs],
264
+ ) -> "ASyncFunctionAsyncDefault[P, T]":
265
+ """
266
+ Decorates a synchronous function with an asynchronous default execution mode.
267
+
268
+ Args:
269
+ coro_fn: The synchronous function to be decorated.
270
+ default: Specifies the default execution mode as 'async'.
271
+ **modifiers: Additional keyword arguments to modify the behavior of the decorated function.
272
+
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
+ """
287
+
288
+
289
+ @overload # async def, sync default
290
+ def a_sync(
291
+ coro_fn: CoroFn[P, T],
292
+ default: Literal["sync"],
293
+ **modifiers: Unpack[ModifierKwargs],
294
+ ) -> ASyncFunctionSyncDefault:
295
+ """
296
+ Decorates an asynchronous function with a synchronous default execution mode.
297
+
298
+ Args:
299
+ coro_fn: The coroutine function to be decorated.
300
+ default: Specifies the default execution mode as 'sync'.
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`
316
+ """
317
+
318
+
319
+ @overload # sync def sync default
320
+ def a_sync(
321
+ coro_fn: SyncFn[P, T],
322
+ default: Literal["sync"],
323
+ **modifiers: Unpack[ModifierKwargs],
324
+ ) -> ASyncFunctionSyncDefault:
325
+ """
326
+ Decorates a synchronous function with a synchronous default execution mode.
327
+
328
+ Args:
329
+ coro_fn: The synchronous function to be decorated.
330
+ default: Specifies the default execution mode as 'sync'.
331
+ **modifiers: Additional keyword arguments to modify the behavior of the decorated function.
332
+
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
+ """
347
+
348
+
349
+ @overload
350
+ def a_sync(
351
+ coro_fn: Literal[None],
352
+ default: Literal["sync"],
353
+ **modifiers: Unpack[ModifierKwargs],
354
+ ) -> ASyncDecoratorSyncDefault:
355
+ """
356
+ Creates a synchronous default decorator with no function specified.
357
+
358
+ Args:
359
+ coro_fn: Specifies no function.
360
+ default: Specifies the default execution mode as 'sync'.
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`
376
+ """
377
+
378
+
379
+ @overload # if you try to use default as the only arg
380
+ def a_sync(
381
+ coro_fn: Literal["sync"],
382
+ default: Literal[None] = None,
383
+ **modifiers: Unpack[ModifierKwargs],
384
+ ) -> ASyncDecoratorSyncDefault:
385
+ """
386
+ Creates a synchronous default decorator with no default execution mode specified.
387
+
388
+ Args:
389
+ coro_fn: Specifies the default execution mode as 'sync'.
390
+ default: Specifies no default execution mode.
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`
406
+ """
407
+
408
+
409
+ @overload # if you try to use default as the only arg
410
+ def a_sync(
411
+ coro_fn: Literal["sync"],
412
+ default: Literal[None],
413
+ **modifiers: Unpack[ModifierKwargs],
414
+ ) -> ASyncDecoratorSyncDefault:
415
+ """
416
+ Creates a synchronous default decorator with no default execution mode specified.
417
+
418
+ Args:
419
+ coro_fn: Specifies the default execution mode as 'sync'.
420
+ default: Specifies no default execution mode.
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`
436
+ """
437
+
438
+
439
+ # catchall
440
+ def a_sync(
441
+ coro_fn: Optional[AnyFn[P, T]] = None,
442
+ default: DefaultMode = config.DEFAULT_MODE,
443
+ # default values are set by passing these kwargs into a ModifierManager object.
444
+ **modifiers: Unpack[ModifierKwargs],
445
+ ) -> Union[ASyncDecorator, "ASyncFunction[P, T]"]:
446
+ """
447
+ A versatile decorator that enables both synchronous and asynchronous execution of functions.
448
+
449
+ This decorator allows a function to be called either synchronously or asynchronously,
450
+ depending on the context and parameters. It provides a powerful way to write code
451
+ that can be used in both synchronous and asynchronous environments.
452
+
453
+ Args:
454
+ coro_fn: The function to be decorated. Can be either a coroutine function or a regular function.
455
+ default: Determines the default execution mode. Can be 'async', 'sync', or None.
456
+ If None, the mode is inferred from the decorated function type.
457
+ **modifiers: Additional keyword arguments to modify the behavior of the decorated function.
458
+ See :class:`ModifierKwargs` for available options.
459
+
460
+ Modifiers:
461
+ The following modifiers can be used to customize the behavior of the decorator:
462
+
463
+ - cache_type: Can be None or 'memory'. 'memory' is an LRU cache which can be modified with
464
+ the 'cache_typed', 'ram_cache_maxsize', and 'ram_cache_ttl' modifiers.
465
+ - cache_typed: Set to True if you want types considered for cache keys. For example, with
466
+ cache_typed=True, Decimal(0) and 0 will be considered separate keys.
467
+ - ram_cache_maxsize: The max size for your LRU cache. None if the cache is unbounded. If you
468
+ set this value without specifying a cache type, 'memory' will automatically be applied.
469
+ - ram_cache_ttl: The TTL for items in your LRU cache. Set to None. If you set this value
470
+ without specifying a cache type, 'memory' will automatically be applied.
471
+ - runs_per_minute: Setting this value enables a rate limiter for the decorated function.
472
+ - semaphore: Drop in a Semaphore for your async defined functions.
473
+ - executor: The executor for the synchronous function. Set to the library's default of
474
+ config.default_sync_executor.
475
+
476
+ Examples:
477
+ The decorator can be used in several ways.
478
+
479
+ 1. As a simple decorator:
480
+ >>> @a_sync
481
+ ... async def some_async_fn():
482
+ ... return True
483
+ >>> await some_async_fn()
484
+ True
485
+ >>> some_async_fn(sync=True)
486
+ True
487
+
488
+ >>> @a_sync
489
+ ... def some_sync_fn():
490
+ ... return True
491
+ >>> some_sync_fn()
492
+ True
493
+ >>> some_sync_fn(sync=False)
494
+ <coroutine object some_sync_fn at 0x7fb4f5fb49c0>
495
+
496
+ 2. As a decorator with default mode specified:
497
+ >>> @a_sync(default='sync')
498
+ ... async def some_fn():
499
+ ... return True
500
+ ...
501
+ >>> some_fn()
502
+ True
503
+ >>> some_fn(sync=False)
504
+ <coroutine object some_fn at 0x7fb4f5fb49c0>
505
+
506
+ >>> @a_sync('async')
507
+ ... def some_fn():
508
+ ... return True
509
+ ...
510
+ >>> some_fn()
511
+ <coroutine object some_fn at 0x7fb4f5fb49c0>
512
+ >>> some_fn(asynchronous=False)
513
+ True
514
+
515
+ 3. As a decorator with modifiers:
516
+ >>> @a_sync(cache_type='memory', runs_per_minute=60)
517
+ ... async def some_fn():
518
+ ... return True
519
+ ...
520
+ >>> some_fn(sync=True)
521
+ True
522
+
523
+ 4. Applied directly to a function:
524
+ >>> some_fn = a_sync(some_existing_function, default='sync')
525
+ >>> some_fn()
526
+ "some return value"
527
+
528
+ The decorated function can then be called either synchronously or asynchronously:
529
+ >>> result = some_fn() # Synchronous call
530
+ >>> result = await some_fn() # Asynchronous call
531
+
532
+ The execution mode can also be explicitly specified during the call:
533
+ >>> result = some_fn(sync=True) # Force synchronous execution
534
+ >>> result = await some_fn(sync=False) # Force asynchronous execution
535
+
536
+ This decorator is particularly useful for libraries that need to support
537
+ both synchronous and asynchronous usage, or for gradually migrating
538
+ synchronous code to asynchronous without breaking existing interfaces.
539
+
540
+ Note:
541
+ If the `coro_fn` argument is passed as 'async' or 'sync', it is treated as the `default` argument,
542
+ and `coro_fn` is set to `None`.
543
+
544
+ See Also:
545
+ :class:`ASyncFunction`, :class:`ASyncDecorator`
546
+ """
547
+
548
+ # If the dev tried passing a default as an arg instead of a kwarg, ie: @a_sync('sync')...
549
+ if coro_fn in ("async", "sync"):
550
+ default = coro_fn # type: ignore [assignment]
551
+ coro_fn = None
552
+
553
+ if default == "sync":
554
+ deco = ASyncDecoratorSyncDefault(default=default, **modifiers)
555
+ elif default == "async":
556
+ deco = ASyncDecoratorAsyncDefault(default=default, **modifiers)
557
+ else:
558
+ deco = ASyncDecorator(default=default, **modifiers)
559
+ return deco if coro_fn is None else deco(coro_fn) # type: ignore [arg-type]
560
+
561
+
562
+ # TODO: in a future release, I will make this usable with sync functions as well