cadwyn 3.15.7__py3-none-any.whl → 3.15.9__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.

Potentially problematic release.


This version of cadwyn might be problematic. Click here for more details.

cadwyn/_asts.py CHANGED
@@ -101,7 +101,7 @@ def transform_generic_alias(value: GenericAliasUnion) -> Any:
101
101
  return f"{get_fancy_repr(get_origin(value))}[{', '.join(get_fancy_repr(a) for a in get_args(value))}]"
102
102
 
103
103
 
104
- def transform_none(_: NoneType) -> Any:
104
+ def transform_none(_: Any) -> Any:
105
105
  return "None"
106
106
 
107
107
 
@@ -156,7 +156,6 @@ def transform_other(value: Any) -> Any:
156
156
  def _get_lambda_source_from_default_factory(source: str) -> str:
157
157
  found_lambdas: list[ast.Lambda] = []
158
158
 
159
- ast.parse(source)
160
159
  for node in ast.walk(ast.parse(source)):
161
160
  if isinstance(node, ast.keyword) and node.arg == "default_factory" and isinstance(node.value, ast.Lambda):
162
161
  found_lambdas.append(node.value)
@@ -232,7 +231,7 @@ def delete_keyword_from_call(attr_name: str, call: ast.Call):
232
231
  def get_ast_keyword_from_argument_name_and_value(name: str, value: Any):
233
232
  if not isinstance(value, ast.AST):
234
233
  value = ast.parse(get_fancy_repr(value), mode="eval").body
235
- return ast.keyword(arg=name, value=value)
234
+ return ast.keyword(arg=name, value=value) # pyright: ignore[reportArgumentType, reportCallIssue]
236
235
 
237
236
 
238
237
  def pop_docstring_from_cls_body(cls_body: list[ast.stmt]) -> list[ast.stmt]:
cadwyn/codegen/_common.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import ast
2
2
  import dataclasses
3
3
  import inspect
4
+ import textwrap
4
5
  from dataclasses import dataclass
5
6
  from enum import Enum
6
7
  from functools import cache
@@ -89,7 +90,7 @@ def get_fields_and_validators_from_model(
89
90
  {},
90
91
  )
91
92
  else:
92
- cls_ast = cast(ast.ClassDef, ast.parse(source).body[0])
93
+ cls_ast = cast(ast.ClassDef, ast.parse(textwrap.dedent(source)).body[0])
93
94
  validators: dict[str, _ValidatorWrapper] = {}
94
95
 
95
96
  validators_and_nones = (
@@ -80,9 +80,9 @@ def _modify_schema_cls(
80
80
  cls_node.name = model_info.name
81
81
 
82
82
  field_definitions = [
83
- ast.AnnAssign(
83
+ ast.AnnAssign( # pyright: ignore[reportCallIssue]
84
84
  target=ast.Name(name, ctx=ast.Store()),
85
- annotation=copy.deepcopy(field.annotation_ast),
85
+ annotation=copy.deepcopy(field.annotation_ast), # pyright: ignore[reportArgumentType]
86
86
  # We do this because next plugins **might** use a transformer which will edit the ast within the field
87
87
  # and break rendering
88
88
  value=copy.deepcopy(field.value_ast),
cadwyn/middleware.py CHANGED
@@ -64,11 +64,11 @@ class HeaderVersioningMiddleware(BaseHTTPMiddleware):
64
64
  request=request,
65
65
  dependant=self.version_header_validation_dependant,
66
66
  async_exit_stack=async_exit_stack,
67
+ embed_body_fields=False,
67
68
  )
68
- values, errors, *_ = solved_result
69
- if errors:
70
- return self.default_response_class(status_code=422, content=_normalize_errors(errors))
71
- api_version = cast(date, values[self.api_version_header_name.replace("-", "_")])
69
+ if solved_result.errors:
70
+ return self.default_response_class(status_code=422, content=_normalize_errors(solved_result.errors))
71
+ api_version = cast(date, solved_result.values[self.api_version_header_name.replace("-", "_")])
72
72
  self.api_version_var.set(api_version)
73
73
 
74
74
  response = await call_next(request)
@@ -445,7 +445,7 @@ def _extract_internal_request_schemas_from_router(
445
445
 
446
446
  def _extract_internal_request_schemas_from_annotations(annotations: dict[str, Any]):
447
447
  for key, annotation in annotations.items():
448
- if isinstance(annotation, type(Annotated[int, int])):
448
+ if isinstance(annotation, type(Annotated[int, int])): # pyright: ignore[reportArgumentType]
449
449
  args = get_args(annotation)
450
450
  if isinstance(args[1], type) and issubclass( # pragma: no branch
451
451
  args[1],
@@ -525,7 +525,7 @@ class _AnnotationTransformer:
525
525
  ):
526
526
  if route.response_model is not None and not ignore_response_model:
527
527
  route.response_model = self._change_version_of_annotations(route.response_model, version_dir)
528
- route.response_field = fastapi.utils.create_response_field(
528
+ route.response_field = fastapi.utils.create_model_field(
529
529
  name="Response_" + route.unique_id,
530
530
  type_=route.response_model,
531
531
  mode="serialization",
@@ -1,5 +1,6 @@
1
1
  import ast
2
2
  import dataclasses
3
+ import textwrap
3
4
  from dataclasses import InitVar, dataclass
4
5
  from types import ModuleType
5
6
 
@@ -13,7 +14,7 @@ class AlterModuleInstruction:
13
14
  import_: ast.Import | ast.ImportFrom = dataclasses.field(init=False)
14
15
 
15
16
  def __post_init__(self, raw_import: str):
16
- parsed_body = ast.parse(raw_import).body
17
+ parsed_body = ast.parse(textwrap.dedent(raw_import)).body
17
18
  if len(parsed_body) > 1:
18
19
  raise CadwynStructureError(
19
20
  f"You have specified more than just a single import. This is prohibited. "
@@ -449,6 +449,8 @@ class VersionBundle:
449
449
  current_version: VersionDate,
450
450
  head_route: APIRoute,
451
451
  exit_stack: AsyncExitStack,
452
+ *,
453
+ embed_body_fields: bool,
452
454
  ) -> dict[str, Any]:
453
455
  method = request.method
454
456
  for v in reversed(self.versions):
@@ -465,19 +467,20 @@ class VersionBundle:
465
467
  request.scope["headers"] = tuple((key.encode(), value.encode()) for key, value in request_info.headers.items())
466
468
  del request._headers
467
469
  # Remember this: if len(body_params) == 1, then route.body_schema == route.dependant.body_params[0]
468
- dependencies, errors, _, _, _ = await solve_dependencies(
470
+ result = await solve_dependencies(
469
471
  request=request,
470
472
  response=response,
471
473
  dependant=head_dependant,
472
474
  body=request_info.body,
473
475
  dependency_overrides_provider=head_route.dependency_overrides_provider,
474
476
  async_exit_stack=exit_stack,
477
+ embed_body_fields=embed_body_fields,
475
478
  )
476
- if errors:
479
+ if result.errors:
477
480
  raise CadwynHeadRequestValidationError(
478
- _normalize_errors(errors), body=request_info.body, version=current_version
481
+ _normalize_errors(result.errors), body=request_info.body, version=current_version
479
482
  )
480
- return dependencies
483
+ return result.values
481
484
 
482
485
  def _migrate_response(
483
486
  self,
@@ -671,7 +674,10 @@ class VersionBundle:
671
674
  # that do not have it. We don't support it too.
672
675
  if response_info.body is not None and hasattr(response_info._response, "body"):
673
676
  # TODO (https://github.com/zmievsa/cadwyn/issues/51): Only do this if there are migrations
674
- if isinstance(response_info.body, str):
677
+ if (
678
+ isinstance(response_info.body, str)
679
+ and response_info._response.headers.get("content-type") != "application/json"
680
+ ):
675
681
  response_info._response.body = response_info.body.encode(response_info._response.charset)
676
682
  else:
677
683
  response_info._response.body = json.dumps(
@@ -752,6 +758,7 @@ class VersionBundle:
752
758
  api_version,
753
759
  head_route,
754
760
  exit_stack=exit_stack,
761
+ embed_body_fields=route._embed_body_fields,
755
762
  )
756
763
  # Because we re-added it into our kwargs when we did solve_dependencies
757
764
  if _CADWYN_REQUEST_PARAM_NAME in new_kwargs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.15.7
3
+ Version: 3.15.9
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Home-page: https://github.com/zmievsa/cadwyn
6
6
  License: MIT
@@ -33,7 +33,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Classifier: Typing :: Typed
34
34
  Provides-Extra: cli
35
35
  Requires-Dist: better-ast-comments (>=1.2.1,<1.3.0)
36
- Requires-Dist: fastapi (>=0.110.0)
36
+ Requires-Dist: fastapi (>=0.115.2)
37
37
  Requires-Dist: issubclass (>=0.1.2,<0.2.0)
38
38
  Requires-Dist: jinja2 (>=3.1.2)
39
39
  Requires-Dist: pydantic (>=1.0.0)
@@ -1,25 +1,25 @@
1
1
  cadwyn/__init__.py,sha256=Wh_CtNgodacy8plxyDXCDb52CDftbql4jGXQ2pldX4s,605
2
2
  cadwyn/__main__.py,sha256=cc-5iYItjxRnB09uxuxlEbjrLm1AEhXI2KrI5iakEOw,4376
3
- cadwyn/_asts.py,sha256=OF1qQKPqTbgYhH1tYF-MB8CCU0r6YITZpMFegzmk0Ic,10118
3
+ cadwyn/_asts.py,sha256=0OcYNZPFm65CFb-oZMwbx191Bai0asqDA4y_IKzh6_w,10147
4
4
  cadwyn/_compat.py,sha256=yAPmfGl2vVEYXlNHHPMoa2JkEJCVPjbP_Uz0WOIVOp4,5494
5
5
  cadwyn/_package_utils.py,sha256=trxTYLmppv-10SKhScfyDQJh21rsQGFoLaOtHycKKR0,1443
6
6
  cadwyn/_utils.py,sha256=BFsfZBpdoL5RMAaT1V1cXJVpTZCmwksQ-Le2MTHivGI,4841
7
7
  cadwyn/applications.py,sha256=MkZ_vMs6YfnfuWPUzBjNBmrxtDa97etsV0zcnlv-iS0,15749
8
8
  cadwyn/codegen/README.md,sha256=hc7AE87LsEsvbh-wX1H10JEWh-8bLHoe-1CkY3h00FI,879
9
9
  cadwyn/codegen/__init__.py,sha256=JgddDjxMTjSfVrMXHwNu1ODgdn2QfPWpccrRKquBV6k,355
10
- cadwyn/codegen/_common.py,sha256=FTI4fqpUFGBMACVlPiDMHTWhqwW_-zQNa_4Qh7m-hCA,5877
10
+ cadwyn/codegen/_common.py,sha256=fnz9Q-C7oZ3JKypPC_Xi6_CssF803XAUHL661IYY1hM,5910
11
11
  cadwyn/codegen/_main.py,sha256=1mpXq_1AuZaAOeGjrCVMhcK7zhjmmlO82Q3ehoOOAfM,10483
12
12
  cadwyn/codegen/_plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  cadwyn/codegen/_plugins/class_migrations.py,sha256=kHZ-RMRTARZ4l70fxHMtul_204Ute2_yQmEej7wMwwo,20119
14
- cadwyn/codegen/_plugins/class_rebuilding.py,sha256=zNlB_VxoEAtdC5Ydiqa7pu6Ka-pKnpPQk_dvovaK0QI,3623
14
+ cadwyn/codegen/_plugins/class_rebuilding.py,sha256=_gjQsx_kU36tf8HT3mKhSv7V9RXfawFdbKTtYLP2IMk,3698
15
15
  cadwyn/codegen/_plugins/class_renaming.py,sha256=oc9Ms6YnpJKaq1iOehcBfA_OFUFL-CAAZJiaQPlkKHs,1773
16
16
  cadwyn/codegen/_plugins/import_auto_adding.py,sha256=krAVzsmsW-CbKP-W9oCkQsL7aPfhHzRq4STgai6Tm5s,2543
17
17
  cadwyn/codegen/_plugins/module_migrations.py,sha256=TeWJk4Iu4SRQ9K2iI3v3sCs1110jrltKlPdfU9mXIsQ,722
18
18
  cadwyn/exceptions.py,sha256=aJKx1qgzZqShL4MX3COjS780qzNJcdZFeGzYYa5gbzw,1726
19
19
  cadwyn/main.py,sha256=kt2Vn7TIA4ZnD_xrgz57TOjUk-4zVP8SV8nuTZBEaaU,218
20
- cadwyn/middleware.py,sha256=8cuBri_yRkl0goe6G0MLwtL04WGbW9Infah3wy9hUVM,3372
20
+ cadwyn/middleware.py,sha256=kUZK2dmoricMbv6knPCIHpXEInX2670XIwAj0v_XQxk,3408
21
21
  cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- cadwyn/route_generation.py,sha256=14_CP_oJBhiO1dNgtYwYkuZnL7o7wyL-EenSvMx39ig,41571
22
+ cadwyn/route_generation.py,sha256=80LmEodZ5SgscnhVL4A3ck0t8RJK5d5Acnefyo4CfIc,41607
23
23
  cadwyn/routing.py,sha256=o6IMjxTxARPa5BxFfsXqOP3bVw9Ya6OBAEbUwH9lMVM,7445
24
24
  cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
@@ -28,11 +28,11 @@ cadwyn/structure/common.py,sha256=6Z4nI97XPWTCinn6np73m-rLPyYNrz2fWXKJlqjsiaQ,26
28
28
  cadwyn/structure/data.py,sha256=1ALPhBBCE_t4GrxM0Fa3hQ-jkORJgeWNySnZ42bsi0g,7382
29
29
  cadwyn/structure/endpoints.py,sha256=JhTgVrqLjm5LkE9thjvU1UuWcSCmDgW2bMdqznsZb2Y,5777
30
30
  cadwyn/structure/enums.py,sha256=iMokxA2QYJ61SzyB-Pmuq3y7KL7-e6TsnjLVUaVZQnw,954
31
- cadwyn/structure/modules.py,sha256=1FK-lLm-zOTXEvn-QtyBH38aDRht5PDQiZrOPCsBlM4,1268
31
+ cadwyn/structure/modules.py,sha256=v3hA_KiqKwwo-ur0Z84WvqD0rTTe4fBTkMUK8SxUj7s,1301
32
32
  cadwyn/structure/schemas.py,sha256=0ylArAkUw626VkUOJSulOwJs7CS6lrGBRECEG5HFD4Q,8897
33
- cadwyn/structure/versions.py,sha256=_NthvvuN7l01J-E2zCZmYtpJZjiVO-wqSDvMSFXhzno,37400
34
- cadwyn-3.15.7.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
35
- cadwyn-3.15.7.dist-info/METADATA,sha256=IplLmVX2LHqfcRse_swuTQ9cf-9MMbbhcKs-10rNhok,4397
36
- cadwyn-3.15.7.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
37
- cadwyn-3.15.7.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
38
- cadwyn-3.15.7.dist-info/RECORD,,
33
+ cadwyn/structure/versions.py,sha256=Vlp-H1K36NRztHRkNhagmNKgQbIP6bc0gAgm7egHCTs,37679
34
+ cadwyn-3.15.9.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
35
+ cadwyn-3.15.9.dist-info/METADATA,sha256=LF_7ygrwYAOOqt8any8RynxqWL0I1hVI5seBiqjy7Rg,4397
36
+ cadwyn-3.15.9.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
37
+ cadwyn-3.15.9.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
38
+ cadwyn-3.15.9.dist-info/RECORD,,