u-toolkit 0.1.13__py3-none-any.whl → 0.1.15__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.
- u_toolkit/decorators.py +40 -1
- {u_toolkit-0.1.13.dist-info → u_toolkit-0.1.15.dist-info}/METADATA +1 -1
- {u_toolkit-0.1.13.dist-info → u_toolkit-0.1.15.dist-info}/RECORD +5 -5
- {u_toolkit-0.1.13.dist-info → u_toolkit-0.1.15.dist-info}/WHEEL +0 -0
- {u_toolkit-0.1.13.dist-info → u_toolkit-0.1.15.dist-info}/entry_points.txt +0 -0
u_toolkit/decorators.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import inspect
|
2
2
|
from collections.abc import Callable
|
3
3
|
from functools import wraps
|
4
|
-
from typing import Generic, NamedTuple, TypeVar
|
4
|
+
from typing import Generic, NamedTuple, ParamSpec, TypeVar
|
5
5
|
|
6
6
|
|
7
7
|
_FnT = TypeVar("_FnT", bound=Callable)
|
@@ -49,3 +49,42 @@ def define_method_handler(
|
|
49
49
|
handle(params)
|
50
50
|
|
51
51
|
return Decorator
|
52
|
+
|
53
|
+
|
54
|
+
_P = ParamSpec("_P")
|
55
|
+
|
56
|
+
_T2 = TypeVar("_T2")
|
57
|
+
|
58
|
+
|
59
|
+
def create_decorator(
|
60
|
+
handle: Callable[_P, _T2] | None = None,
|
61
|
+
use_handle_return: bool | None = None,
|
62
|
+
):
|
63
|
+
def decorator(fn: Callable[_P, _T]):
|
64
|
+
if inspect.iscoroutinefunction(fn):
|
65
|
+
|
66
|
+
@wraps(fn)
|
67
|
+
async def async_wrapper(*args, **kwargs):
|
68
|
+
handle_result = None
|
69
|
+
if inspect.iscoroutinefunction(handle):
|
70
|
+
handle_result = await handle(*args, **kwargs)
|
71
|
+
elif handle:
|
72
|
+
handle_result = handle(*args, **kwargs)
|
73
|
+
if use_handle_return:
|
74
|
+
return handle_result
|
75
|
+
return await fn(*args, **kwargs)
|
76
|
+
|
77
|
+
return async_wrapper
|
78
|
+
|
79
|
+
@wraps(fn)
|
80
|
+
def wrapper(*args: _P.args, **kwargs: _P.kwargs):
|
81
|
+
if handle:
|
82
|
+
handle_result = handle(*args, **kwargs)
|
83
|
+
if use_handle_return:
|
84
|
+
return handle_result
|
85
|
+
|
86
|
+
return fn(*args, **kwargs)
|
87
|
+
|
88
|
+
return wrapper
|
89
|
+
|
90
|
+
return decorator
|
@@ -1,7 +1,7 @@
|
|
1
1
|
u_toolkit/__init__.py,sha256=7f_bFg1UERA4gyh3HjCAjOZo2cBUgElpwgX5x-Xk2WA,238
|
2
2
|
u_toolkit/alias_generators.py,sha256=KmPL1ViGJjptONffZUAX4ENvkldrwDylm_Ly5RYE8b4,963
|
3
3
|
u_toolkit/datetime.py,sha256=GOG0xa6yKeqvFXJkImK5Pt7wsPXnHMlNKju8deniGJ4,644
|
4
|
-
u_toolkit/decorators.py,sha256=
|
4
|
+
u_toolkit/decorators.py,sha256=rBZfXtWVfja6YMDqF9izjAiabRVyp4pAWOlwnN0HkUw,2396
|
5
5
|
u_toolkit/enum.py,sha256=2yWmK8V1q0P5S3ltBED-TF2H09BmRbsBuqu3Th3G1NE,862
|
6
6
|
u_toolkit/function.py,sha256=GAE6TIm5jpemUiNUPjzk7pIHrxwSSX7sHl1V5E735dE,252
|
7
7
|
u_toolkit/helpers.py,sha256=K3FCz93K1nT4o7gWKVpMKy3k3BnirTPCSb8F8EFUrWk,112
|
@@ -30,7 +30,7 @@ u_toolkit/sqlalchemy/type_vars.py,sha256=m2VeV41CBIK_1QX3w2kgz-n556sILAGZ-Kaz3TD
|
|
30
30
|
u_toolkit/sqlalchemy/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
31
|
u_toolkit/sqlalchemy/orm/fields.py,sha256=3zoYil23I6YLtc_59aHDt9w5l1NBTkePT9AfXI3DMiY,593
|
32
32
|
u_toolkit/sqlalchemy/orm/models.py,sha256=V8vf4ps3phAmwxyaFYK7pw8Igz7h097o4QBjKB0gwC8,705
|
33
|
-
u_toolkit-0.1.
|
34
|
-
u_toolkit-0.1.
|
35
|
-
u_toolkit-0.1.
|
36
|
-
u_toolkit-0.1.
|
33
|
+
u_toolkit-0.1.15.dist-info/METADATA,sha256=9YW-ZY96UyD1LCdAKjIGAVWbvOM8mqaCvcP-152uIVU,366
|
34
|
+
u_toolkit-0.1.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
35
|
+
u_toolkit-0.1.15.dist-info/entry_points.txt,sha256=hTfAYCd5vvRiqgnJk2eBsoRIiIVB9pK8WZm3Q3jjKFU,45
|
36
|
+
u_toolkit-0.1.15.dist-info/RECORD,,
|
File without changes
|
File without changes
|