u-toolkit 0.1.3__tar.gz → 0.1.5__tar.gz

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.
Files changed (41) hide show
  1. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/PKG-INFO +1 -1
  2. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/pyproject.toml +1 -1
  3. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/cbv.py +33 -12
  4. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/signature.py +2 -3
  5. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/tests/fastapi/test_cbv.py +13 -6
  6. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/.github/workflows/publish.yml +0 -0
  7. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/.gitignore +0 -0
  8. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/README.md +0 -0
  9. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/__init__.py +0 -0
  10. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/alias_generators.py +0 -0
  11. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/datetime.py +0 -0
  12. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/decorators.py +0 -0
  13. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/enum.py +0 -0
  14. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/__init__.py +0 -0
  15. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/config.py +0 -0
  16. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/exception.py +0 -0
  17. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/helpers.py +0 -0
  18. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/lifespan.py +0 -0
  19. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/pagination.py +0 -0
  20. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/fastapi/responses.py +0 -0
  21. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/function.py +0 -0
  22. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/helpers.py +0 -0
  23. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/logger.py +0 -0
  24. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/merge.py +0 -0
  25. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/object.py +0 -0
  26. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/path.py +0 -0
  27. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/pydantic/__init__.py +0 -0
  28. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/pydantic/fields.py +0 -0
  29. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/pydantic/models.py +0 -0
  30. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/pydantic/type_vars.py +0 -0
  31. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/__init__.py +0 -0
  32. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/fields.py +0 -0
  33. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/function.py +0 -0
  34. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/orm/__init__.py +0 -0
  35. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/orm/fields.py +0 -0
  36. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/orm/models.py +0 -0
  37. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/table_info.py +0 -0
  38. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/src/u_toolkit/sqlalchemy/type_vars.py +0 -0
  39. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/tests/__init__.py +0 -0
  40. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/tests/fastapi/__init__.py +0 -0
  41. {u_toolkit-0.1.3 → u_toolkit-0.1.5}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u-toolkit
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: pydantic>=2.11.3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "u-toolkit"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -13,7 +13,11 @@ from u_toolkit.fastapi.helpers import get_depend_from_annotation, is_depend
13
13
  from u_toolkit.fastapi.responses import Response, build_responses
14
14
  from u_toolkit.helpers import is_annotated
15
15
  from u_toolkit.merge import deep_merge_dict
16
- from u_toolkit.signature import update_parameters, with_parameter
16
+ from u_toolkit.signature import (
17
+ list_parameters,
18
+ update_parameters,
19
+ with_parameter,
20
+ )
17
21
 
18
22
 
19
23
  class EndpointsClassInterface(Protocol):
@@ -304,7 +308,16 @@ class CBV:
304
308
  for name, dep in iter_dependencies(cls)
305
309
  ]
306
310
 
307
- update_parameters(collect_cls_dependencies, *parameters)
311
+ has_cls_deps = bool(parameters)
312
+ if has_cls_deps:
313
+ update_parameters(collect_cls_dependencies, *parameters)
314
+
315
+ def new_fn(method_name, kwargs):
316
+ instance = self._build_cls(cls)
317
+ dependencies = kwargs.pop(collect_cls_dependencies.__name__)
318
+ for dep_name, dep_value in dependencies.items():
319
+ setattr(instance, dep_name, dep_value)
320
+ return getattr(instance, method_name)
308
321
 
309
322
  def decorator(method: Callable):
310
323
  method_name = method.__name__
@@ -313,21 +326,29 @@ class CBV:
313
326
  sign_cls_fn = partial(cls_fn)
314
327
  update_wrapper(sign_cls_fn, cls_fn)
315
328
 
316
- parameters, *_ = with_parameter(
317
- sign_cls_fn,
318
- name=collect_cls_dependencies.__name__,
319
- default=Depends(collect_cls_dependencies),
320
- )
329
+ if has_cls_deps:
330
+ parameters, *_ = with_parameter(
331
+ sign_cls_fn,
332
+ name=collect_cls_dependencies.__name__,
333
+ default=Depends(collect_cls_dependencies),
334
+ )
335
+ else:
336
+ parameters = list_parameters(sign_cls_fn)
321
337
 
322
338
  update_parameters(sign_cls_fn, *(parameters[1:]))
323
339
 
340
+ if inspect.iscoroutinefunction(method):
341
+
342
+ @wraps(sign_cls_fn)
343
+ async def awrapper(*args, **kwargs):
344
+ fn = new_fn(method_name, kwargs)
345
+ return await fn(*args, **kwargs)
346
+
347
+ return awrapper
348
+
324
349
  @wraps(sign_cls_fn)
325
350
  def wrapper(*args, **kwargs):
326
- instance = self._build_cls(cls)
327
- dependencies = kwargs.pop(collect_cls_dependencies.__name__)
328
- for dep_name, dep_value in dependencies.items():
329
- setattr(instance, dep_name, dep_value)
330
- fn = getattr(instance, method_name)
351
+ fn = new_fn(method_name, kwargs)
331
352
  return fn(*args, **kwargs)
332
353
 
333
354
  return wrapper
@@ -1,6 +1,5 @@
1
1
  import inspect
2
2
  from collections.abc import Callable, Sequence
3
- from functools import partial
4
3
  from typing import Annotated, Any, overload
5
4
 
6
5
 
@@ -57,9 +56,9 @@ def update_signature(
57
56
  return_annotation: type | None = None,
58
57
  ):
59
58
  signature = inspect.signature(fn)
60
- if parameters:
59
+ if parameters is not None:
61
60
  signature = signature.replace(parameters=parameters)
62
- if return_annotation:
61
+ if return_annotation is not None:
63
62
  signature = signature.replace(return_annotation=return_annotation)
64
63
 
65
64
  setattr(fn, "__signature__", signature)
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  from typing import Annotated, cast
2
3
 
3
4
  import sqlalchemy as sa
@@ -56,17 +57,21 @@ class R:
56
57
  def get(self):
57
58
  return self.value, self.value2, self.value3
58
59
 
59
- @cbv.info(status=status.HTTP_201_CREATED)
60
- def post(self):
61
- record = self.db_dep.execute(sa.text(f"select '{RESULT}'")).one()
62
- return record[0]
63
-
64
60
  def get__wtf____(self):
65
61
  pass
66
62
 
67
63
  @cbv.info(path="/lalala")
68
64
  def get_custom(self): ...
69
65
 
66
+ async def get_async_value(self):
67
+ await asyncio.sleep(0.001)
68
+ return 1
69
+
70
+ @cbv.info(status=status.HTTP_201_CREATED)
71
+ def post(self):
72
+ record = self.db_dep.execute(sa.text(f"select '{RESULT}'")).one()
73
+ return record[0]
74
+
70
75
 
71
76
  @cbv
72
77
  class _NoPath:
@@ -85,7 +90,9 @@ client = TestClient(app)
85
90
 
86
91
  def test_cbv():
87
92
  assert client.get("/r").json() == [dep1_value, dep2_value, dep3_value]
88
- assert client.get("/_wtf____").is_success
93
+ assert client.get("/r/_wtf//").is_success
94
+ assert client.get("/lalala").is_success
95
+ assert client.get("/r/async_value").json() == 1
89
96
 
90
97
  post_resp = client.post("/r")
91
98
  assert post_resp.status_code == status.HTTP_201_CREATED
File without changes
File without changes
File without changes
File without changes