u-toolkit 0.1.15__py3-none-any.whl → 0.1.18__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/fastapi/cbv.py CHANGED
@@ -163,21 +163,31 @@ class CBVRoutesInfo(TypedDict):
163
163
  deprecated: NotRequired[bool | None]
164
164
 
165
165
 
166
+ CBVRoutesInfoT = TypeVar("CBVRoutesInfoT", bound=CBVRoutesInfo)
167
+
168
+
166
169
  class CBVRouteInfo(CBVRoutesInfo, Generic[_T]):
167
170
  methods: NotRequired[list[RequestMethod] | None]
168
171
  response_model: NotRequired[type[_T] | None]
169
172
  status: NotRequired[int | None]
173
+ summary: NotRequired[str | None]
174
+ description: NotRequired[str | None]
175
+ name: NotRequired[str | None]
170
176
 
171
177
 
172
- class CBV:
178
+ class CBV(Generic[CBVRoutesInfoT]):
173
179
  def __init__(self, router: APIRouter | None = None) -> None:
174
180
  self.router = router or APIRouter()
175
181
 
176
- self._state: dict[type, dict[_FnName, CBVRouteInfo]] = {}
177
- self._cls_routes_extra: dict[
178
- type, tuple[CBVRoutesInfo, Callable[[type[_T]], _T] | None] # type: ignore
182
+ self.state: dict[type, dict[_FnName, CBVRouteInfo]] = {}
183
+ self.routes_extra: dict[
184
+ type,
185
+ tuple[
186
+ CBVRoutesInfoT | None,
187
+ Callable[[type[_T]], _T] | None, # type: ignore
188
+ ],
179
189
  ] = {}
180
- self._initialed_state: dict[type[_T], _T] = {} # type: ignore
190
+ self.initialed_state: dict[type[_T], _T] = {} # type: ignore
181
191
 
182
192
  def create_route(
183
193
  self,
@@ -187,41 +197,44 @@ class CBV:
187
197
  method: RequestMethod,
188
198
  method_name: str,
189
199
  ):
190
- class_routes_info = self._cls_routes_extra[cls][0]
200
+ class_routes_info = self.routes_extra[cls][0] or {}
191
201
 
192
202
  class_tags = class_routes_info.get("tags") or []
193
203
  endpoint_tags: list[str | Enum] = (
194
- self._state[cls][method_name].get("tags") or []
204
+ self.state[cls][method_name].get("tags") or []
195
205
  )
196
206
  tags = class_tags + endpoint_tags
197
207
 
198
208
  class_dependencies = class_routes_info.get("dependencies") or []
199
209
  endpoint_dependencies = (
200
- self._state[cls][method_name].get("dependencies") or []
210
+ self.state[cls][method_name].get("dependencies") or []
201
211
  )
202
212
  dependencies = class_dependencies + endpoint_dependencies
203
213
 
204
214
  class_responses = class_routes_info.get("responses") or []
205
215
  endpoint_responses = (
206
- self._state[cls][method_name].get("responses") or []
216
+ self.state[cls][method_name].get("responses") or []
207
217
  )
208
218
  responses = build_responses(*class_responses, *endpoint_responses)
209
219
 
210
- status_code = self._state[cls][method_name].get("status")
220
+ status_code = self.state[cls][method_name].get("status")
211
221
 
212
- deprecated = self._state[cls][method_name].get(
222
+ deprecated = self.state[cls][method_name].get(
213
223
  "deprecated", class_routes_info.get("deprecated")
214
224
  )
215
225
 
216
- response_model = self._state[cls][method_name].get("response_model")
226
+ response_model = self.state[cls][method_name].get("response_model")
217
227
 
218
228
  endpoint_methods = [
219
229
  i.upper()
220
- for i in (self._state[cls][method_name].get("methods") or [method])
230
+ for i in (self.state[cls][method_name].get("methods") or [method])
221
231
  ]
222
232
 
223
- path = self._state[cls][method_name].get("path") or path
233
+ path = self.state[cls][method_name].get("path") or path
224
234
 
235
+ summary = self.state[cls][method_name].get("summary")
236
+ description = self.state[cls][method_name].get("description")
237
+ name = self.state[cls][method_name].get("name")
225
238
  return self.router.api_route(
226
239
  path,
227
240
  methods=endpoint_methods,
@@ -231,9 +244,12 @@ class CBV:
231
244
  responses=responses,
232
245
  status_code=status_code,
233
246
  deprecated=deprecated,
247
+ summary=summary,
248
+ description=description,
249
+ name=name,
234
250
  )
235
251
 
236
- def info(
252
+ def info( # noqa: PLR0913
237
253
  self,
238
254
  *,
239
255
  path: str | None = None,
@@ -242,10 +258,13 @@ class CBV:
242
258
  dependencies: list | None = None,
243
259
  responses: list[Response] | None = None,
244
260
  response_model: type[_T] | None = None,
261
+ summary: str | None = None,
262
+ description: str | None = None,
263
+ name: str | None = None,
245
264
  status: int | None = None,
246
265
  deprecated: bool | None = None,
247
266
  ):
248
- state = self._state
267
+ state = self.state
249
268
  initial_state = self._initial_state
250
269
  data = CBVRouteInfo(
251
270
  path=path,
@@ -256,6 +275,9 @@ class CBV:
256
275
  response_model=response_model,
257
276
  status=status,
258
277
  deprecated=deprecated,
278
+ summary=summary,
279
+ description=description,
280
+ name=name,
259
281
  )
260
282
 
261
283
  def handle(params: DefineMethodParams):
@@ -268,22 +290,20 @@ class CBV:
268
290
  return define_method_handler(handle)
269
291
 
270
292
  def _initial_state(self, cls: type[_T]) -> _T:
271
- if result := self._initialed_state.get(cls):
293
+ if result := self.initialed_state.get(cls):
272
294
  return cast(_T, result)
273
295
 
274
296
  default_data = {}
275
297
  for endpoint in iter_endpoints(cls):
276
298
  default_data[endpoint.original_handle_name] = {}
277
299
 
278
- self._state.setdefault(cls, default_data)
300
+ self.state.setdefault(cls, default_data)
279
301
  result = self._build_cls(cls)
280
- self._initialed_state[cls] = result
302
+ self.initialed_state[cls] = result
281
303
  return result
282
304
 
283
305
  def _build_cls(self, cls: type[_T]) -> _T:
284
- if cls in self._cls_routes_extra and (
285
- build := self._cls_routes_extra[cls][1]
286
- ):
306
+ if cls in self.routes_extra and (build := self.routes_extra[cls][1]):
287
307
  return build(cls) # type: ignore
288
308
  return cls()
289
309
 
@@ -366,24 +386,24 @@ class CBV:
366
386
  def __call__(
367
387
  self,
368
388
  *,
369
- info: CBVRoutesInfo | None = None,
389
+ info: CBVRoutesInfoT | None = None,
370
390
  build: Callable[[type[_T]], _T] | None = None,
371
391
  ) -> Callable[[type[_T]], type[_T]]: ...
372
392
 
373
393
  def __call__(self, *args, **kwargs):
374
- info: CBVRoutesInfo = {}
394
+ info = None
375
395
  build: Callable | None = None
376
396
 
377
397
  def decorator(cls: type[_T]) -> type[_T]:
378
398
  instance = self._initial_state(cls)
379
- self._cls_routes_extra[cls] = info, build
399
+ self.routes_extra[cls] = info, build
380
400
 
381
401
  decorator = self.__create_class_dependencies_injector(cls)
382
402
 
383
403
  def valid_method(
384
404
  name: str, _handle: Callable
385
405
  ) -> None | list[_MethodInfo]:
386
- if (cls_state := self._state.get(cls)) and (
406
+ if (cls_state := self.state.get(cls)) and (
387
407
  method_state := cls_state.get(name)
388
408
  ):
389
409
  methods: list[RequestMethod] = (
@@ -414,7 +434,7 @@ class CBV:
414
434
  if args:
415
435
  return decorator(args[0])
416
436
 
417
- info.update(kwargs.get("info") or {})
437
+ info = kwargs.get("info") or None
418
438
  build = kwargs.get("build")
419
439
 
420
440
  return decorator
@@ -97,7 +97,7 @@ class NamedHTTPError(Exception, Generic[WrapperErrorT, BaseModelT]):
97
97
  ) -> None:
98
98
  kwargs: dict[str, Any] = {
99
99
  "code": self.error_code(),
100
- "message": message or "operation failed",
100
+ "message": message or self.message or "operation failed",
101
101
  }
102
102
 
103
103
  if target:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u-toolkit
3
- Version: 0.1.15
3
+ Version: 0.1.18
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: pydantic>=2.11.3
@@ -11,9 +11,9 @@ u_toolkit/object.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  u_toolkit/path.py,sha256=IkyIHcU9hKBCOZfF30FrKf4CfL-MH91fjeYF9EY7eos,128
12
12
  u_toolkit/signature.py,sha256=-Q6n28PYBYYdd2OXBKESeVkL2rYpV6EaY3IVwQmzezQ,2161
13
13
  u_toolkit/fastapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- u_toolkit/fastapi/cbv.py,sha256=q9A4HKguOVBfLeZmhnY9kfiP6FfAViZUo52m-5aKZhU,12219
14
+ u_toolkit/fastapi/cbv.py,sha256=vRYGeopzduO7Gmf5O5oz76zGOYqFtD8aGAe1oCcK8R4,12910
15
15
  u_toolkit/fastapi/config.py,sha256=kGpokR9XXr1KxMA1GVKYkCdKwqIQAIwOJ-v6sGbqzAQ,267
16
- u_toolkit/fastapi/exception.py,sha256=P9apEEQvbBMmffiHX57768gmemMeAy69-nb-1JQZAZE,4624
16
+ u_toolkit/fastapi/exception.py,sha256=iZy1kjNkhtkLw6nl5x0_g3uvgpkpwutEsjfB7VvX9M0,4640
17
17
  u_toolkit/fastapi/helpers.py,sha256=BCMMLxa1c6BMA_rKq-hCi0iyEjrR3Z5rPMeTvgaVJB0,447
18
18
  u_toolkit/fastapi/lifespan.py,sha256=W1TwWymW7xtmntx59QBC4LQ6xQr3L7yuMMGj4U8hhTQ,1813
19
19
  u_toolkit/fastapi/pagination.py,sha256=yOgEDUT04m_mZ0cPliuDbUHLFnmxGAmr5PyZlwfjT_s,1940
@@ -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.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,,
33
+ u_toolkit-0.1.18.dist-info/METADATA,sha256=sUdl21yodtOf2SmY7zrlZn6YAMM8M0A_KFcwopsTt3I,366
34
+ u_toolkit-0.1.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
35
+ u_toolkit-0.1.18.dist-info/entry_points.txt,sha256=hTfAYCd5vvRiqgnJk2eBsoRIiIVB9pK8WZm3Q3jjKFU,45
36
+ u_toolkit-0.1.18.dist-info/RECORD,,