u-toolkit 0.1.1__py3-none-any.whl → 0.1.3__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 CHANGED
@@ -27,7 +27,8 @@ class DefineMethodDecorator(Generic[_T, _FnT]):
27
27
  self.register_method(DefineMethodParams(owner_class, name, self.fn))
28
28
 
29
29
  def __get__(self, instance: _T, owner_class: type[_T]):
30
- update_parameters(self.fn, *list_parameters(self.fn)[1:])
30
+ parameters = list_parameters(self.fn)[1:]
31
+ update_parameters(self.fn, *parameters)
31
32
 
32
33
  @wraps(self.fn)
33
34
  def wrapper(*args, **kwargs):
u_toolkit/fastapi/cbv.py CHANGED
@@ -24,7 +24,8 @@ class EndpointsClassInterface(Protocol):
24
24
  deprecated: bool | None = None
25
25
 
26
26
  @classmethod
27
- def build_self(cls) -> Self: ...
27
+ def build_self(cls) -> Self:
28
+ return cls()
28
29
 
29
30
 
30
31
  _T = TypeVar("_T")
@@ -68,7 +69,8 @@ class Methods(StrEnum):
68
69
 
69
70
 
70
71
  METHOD_PATTERNS = {
71
- method: re.compile(f"^{method}", re.IGNORECASE) for method in Methods
72
+ method: re.compile(f"^({method}_|{method})", re.IGNORECASE)
73
+ for method in Methods
72
74
  }
73
75
 
74
76
  _FnName = str
@@ -107,7 +109,7 @@ def iter_endpoints(cls: type[_T]):
107
109
  paths = [prefix]
108
110
 
109
111
  if method := get_method(name):
110
- path = method[1].sub(name, "").replace("__", "/")
112
+ path = method[1].sub("", name).replace("__", "/")
111
113
  if path:
112
114
  paths.append(path)
113
115
 
@@ -136,6 +138,7 @@ def iter_dependencies(cls: type[_T]):
136
138
 
137
139
 
138
140
  _CBVEndpointParamName = Literal[
141
+ "path",
139
142
  "tags",
140
143
  "dependencies",
141
144
  "responses",
@@ -197,6 +200,8 @@ class CBV:
197
200
  method
198
201
  ]
199
202
 
203
+ path = self._state[cls][method_name].get("path") or path
204
+
200
205
  return self.router.api_route(
201
206
  path,
202
207
  methods=endpoint_methods,
@@ -211,6 +216,7 @@ class CBV:
211
216
  def info(
212
217
  self,
213
218
  *,
219
+ path: str | None = None,
214
220
  methods: list[Methods | LiteralUpperMethods | LiteralLowerMethods]
215
221
  | None = None,
216
222
  tags: list[str | Enum] | None = None,
@@ -223,6 +229,7 @@ class CBV:
223
229
  state = self._state
224
230
  initial_state = self._initial_state
225
231
  data: dict[_CBVEndpointParamName, Any] = {
232
+ "path": path,
226
233
  "methods": methods,
227
234
  "tags": tags,
228
235
  "dependencies": dependencies,
@@ -296,26 +303,31 @@ class CBV:
296
303
  )
297
304
  for name, dep in iter_dependencies(cls)
298
305
  ]
306
+
299
307
  update_parameters(collect_cls_dependencies, *parameters)
300
308
 
301
309
  def decorator(method: Callable):
302
- sign_fn = partial(method)
303
- update_wrapper(sign_fn, method)
310
+ method_name = method.__name__
311
+
312
+ cls_fn = getattr(cls, method_name)
313
+ sign_cls_fn = partial(cls_fn)
314
+ update_wrapper(sign_cls_fn, cls_fn)
304
315
 
305
316
  parameters, *_ = with_parameter(
306
- method,
317
+ sign_cls_fn,
307
318
  name=collect_cls_dependencies.__name__,
308
319
  default=Depends(collect_cls_dependencies),
309
320
  )
310
- update_parameters(sign_fn, *parameters)
311
321
 
312
- @wraps(sign_fn)
322
+ update_parameters(sign_cls_fn, *(parameters[1:]))
323
+
324
+ @wraps(sign_cls_fn)
313
325
  def wrapper(*args, **kwargs):
314
326
  instance = self._build_cls(cls)
315
327
  dependencies = kwargs.pop(collect_cls_dependencies.__name__)
316
328
  for dep_name, dep_value in dependencies.items():
317
329
  setattr(instance, dep_name, dep_value)
318
- fn = getattr(instance, method.__name__)
330
+ fn = getattr(instance, method_name)
319
331
  return fn(*args, **kwargs)
320
332
 
321
333
  return wrapper
u_toolkit/signature.py CHANGED
@@ -57,13 +57,12 @@ def update_signature(
57
57
  return_annotation: type | None = None,
58
58
  ):
59
59
  signature = inspect.signature(fn)
60
- kwargs = {}
61
60
  if parameters:
62
- kwargs["parameters"] = parameters
61
+ signature = signature.replace(parameters=parameters)
63
62
  if return_annotation:
64
- kwargs["return_annotation"] = return_annotation
63
+ signature = signature.replace(return_annotation=return_annotation)
65
64
 
66
- fn.__signature__ = signature.replace(**kwargs) # type: ignore
65
+ setattr(fn, "__signature__", signature)
67
66
 
68
67
 
69
68
  def update_parameters(fn: Callable, *parameters: inspect.Parameter):
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u-toolkit
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: pydantic>=2.11.3
7
7
  Provides-Extra: fastapi
8
+ Requires-Dist: fastapi>=0.115.12; extra == 'fastapi'
8
9
  Requires-Dist: pydantic-settings>=2.9.1; extra == 'fastapi'
9
10
  Provides-Extra: sqlalchemy
10
11
  Requires-Dist: sqlalchemy>=2.0.40; extra == 'sqlalchemy'
@@ -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=i6dCahV4AHQPwpW48Q55vxMYvcq8GC1noq1SpVE-xjE,1229
4
+ u_toolkit/decorators.py,sha256=NVQPvl8nByo11IRVtAi_kRRjhGvuHPlEme4dYTGZU0s,1261
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
@@ -9,9 +9,9 @@ u_toolkit/logger.py,sha256=NOmdR24QfSuo1EMnetyFioa8pA8OYceYTlQ4qiQcBdE,209
9
9
  u_toolkit/merge.py,sha256=kHrloud-nPti5j48zkdvaiy4mIJYqOVguixAjWC46kE,924
10
10
  u_toolkit/object.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  u_toolkit/path.py,sha256=IkyIHcU9hKBCOZfF30FrKf4CfL-MH91fjeYF9EY7eos,128
12
- u_toolkit/signature.py,sha256=jjIhyqTV3XL_tjPeA4l8dFnF5TybHd4AHF_g_2G2uAg,2168
12
+ u_toolkit/signature.py,sha256=wXyGFgb_E68xevYWx7gIy9P5lVZmHUebpf2EGI_fCnw,2167
13
13
  u_toolkit/fastapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- u_toolkit/fastapi/cbv.py,sha256=fuZCe6An75D3ernxFk6BLta_27VpoXvxBgwhToiCMIA,9940
14
+ u_toolkit/fastapi/cbv.py,sha256=DDkScAD0ab3ws4rRamy-Fw_TXzbpsCTY99xzzlqfXy8,10225
15
15
  u_toolkit/fastapi/config.py,sha256=kGpokR9XXr1KxMA1GVKYkCdKwqIQAIwOJ-v6sGbqzAQ,267
16
16
  u_toolkit/fastapi/exception.py,sha256=5E4wAJYwp0RJ4SEBVkchOgrgfwCgniQ8Mtg1O5sWUXE,3288
17
17
  u_toolkit/fastapi/helpers.py,sha256=BCMMLxa1c6BMA_rKq-hCi0iyEjrR3Z5rPMeTvgaVJB0,447
@@ -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.1.dist-info/METADATA,sha256=DBFOvqAnvvO1KZYL_IQl4hP2WyTA0qgK0RopSxsMmqM,312
34
- u_toolkit-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
35
- u_toolkit-0.1.1.dist-info/entry_points.txt,sha256=hTfAYCd5vvRiqgnJk2eBsoRIiIVB9pK8WZm3Q3jjKFU,45
36
- u_toolkit-0.1.1.dist-info/RECORD,,
33
+ u_toolkit-0.1.3.dist-info/METADATA,sha256=4ibTb4RAFOVw_aJ4Ays4FxrhsjY9IZhpWFIPhkjFcuo,365
34
+ u_toolkit-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
35
+ u_toolkit-0.1.3.dist-info/entry_points.txt,sha256=hTfAYCd5vvRiqgnJk2eBsoRIiIVB9pK8WZm3Q3jjKFU,45
36
+ u_toolkit-0.1.3.dist-info/RECORD,,