cadwyn 4.5.0__py3-none-any.whl → 4.6.0__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/applications.py CHANGED
@@ -279,7 +279,7 @@ class Cadwyn(FastAPI):
279
279
  except (ValueError, TypeError):
280
280
  version = raw_version
281
281
 
282
- if version in self.router.versioned_routers:
282
+ if isinstance(version, date) and version in self.router.versioned_routers:
283
283
  routes = self.router.versioned_routers[version].routes
284
284
  formatted_version = version.isoformat()
285
285
  elif version == "unversioned" and self._there_are_public_unversioned_routes():
@@ -296,7 +296,7 @@ class Cadwyn(FastAPI):
296
296
  self.servers.insert(0, {"url": root_path})
297
297
 
298
298
  webhook_routes = None
299
- if version in self._versioned_webhook_routers:
299
+ if isinstance(version, date) and version in self._versioned_webhook_routers:
300
300
  webhook_routes = self._versioned_webhook_routers[version].routes
301
301
 
302
302
  return JSONResponse(
@@ -40,6 +40,7 @@ from pydantic._internal._decorators import (
40
40
  RootValidatorDecoratorInfo,
41
41
  ValidatorDecoratorInfo,
42
42
  )
43
+ from pydantic._internal._typing_extra import try_eval_type as pydantic_try_eval_type
43
44
  from pydantic.fields import ComputedFieldInfo, FieldInfo
44
45
  from typing_extensions import Doc, Self, _AnnotatedAlias, assert_never
45
46
 
@@ -231,6 +232,12 @@ def _is_dunder(attr_name: str):
231
232
 
232
233
 
233
234
  def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapper[_T_PYDANTIC_MODEL]":
235
+ # In case we have a forwardref within one of the fields
236
+ # For example, when "from __future__ import annotations" is used in the file with the schema
237
+ if model is not BaseModel:
238
+ model.model_rebuild(raise_errors=False)
239
+ model = cast(type[_T_PYDANTIC_MODEL], model)
240
+
234
241
  decorators = _get_model_decorators(model)
235
242
  validators = {}
236
243
  for decorator_wrapper in decorators:
@@ -239,8 +246,20 @@ def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapp
239
246
 
240
247
  wrapped_validator = _wrap_validator(decorator_wrapper.func, decorator_wrapper.shim, decorator_wrapper.info)
241
248
  validators[decorator_wrapper.cls_var_name] = wrapped_validator
249
+
250
+ annotations = {
251
+ name: value
252
+ if not isinstance(value, str)
253
+ else model.model_fields[name].annotation or model.__annotations__[name]
254
+ for name, value in model.__annotations__.items()
255
+ }
256
+
242
257
  fields = {
243
- field_name: PydanticFieldWrapper(model.model_fields[field_name], model.__annotations__[field_name], field_name)
258
+ field_name: PydanticFieldWrapper(
259
+ model.model_fields[field_name],
260
+ annotations[field_name],
261
+ field_name,
262
+ )
244
263
  for field_name in model.__annotations__
245
264
  }
246
265
 
@@ -263,7 +282,7 @@ def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapp
263
282
  fields=fields,
264
283
  other_attributes=other_attributes,
265
284
  validators=validators,
266
- annotations=model.__annotations__.copy(),
285
+ annotations=annotations,
267
286
  )
268
287
 
269
288
 
@@ -355,6 +374,7 @@ class _PydanticModelWrapper(Generic[_T_PYDANTIC_MODEL]):
355
374
  if not validator.is_deleted and type(validator) == _ValidatorWrapper # noqa: E721
356
375
  }
357
376
  fields = {name: field.generate_field_copy(generator) for name, field in self.fields.items()}
377
+
358
378
  model_copy = type(self.cls)(
359
379
  self.name,
360
380
  tuple(generator[cast(type[BaseModel], base)] for base in self.cls.__bases__),
@@ -418,6 +438,7 @@ class _AnnotationTransformer:
418
438
  # because such copies could produce weird behaviors at runtime, especially if you/fastapi do any comparisons.
419
439
  # It's defined here and not on the method because of this: https://youtu.be/sVjtp6tGo0g
420
440
  self.generator = generator
441
+ # TODO: Rewrite this to memoize
421
442
  self.change_versions_of_a_non_container_annotation = functools.cache(
422
443
  self._change_version_of_a_non_container_annotation
423
444
  )
@@ -531,6 +552,9 @@ class _AnnotationTransformer:
531
552
  annotation_modifying_wrapper = annotation_modifying_wrapper_factory(call)
532
553
  old_params = inspect.signature(call).parameters
533
554
  callable_annotations = annotation_modifying_wrapper.__annotations__
555
+ callable_annotations = {
556
+ k: v if type(v) is not str else _try_eval_type(v, call.__globals__) for k, v in callable_annotations.items()
557
+ }
534
558
  annotation_modifying_wrapper.__annotations__ = modify_annotations(callable_annotations)
535
559
  annotation_modifying_wrapper.__defaults__ = modify_defaults(
536
560
  tuple(p.default for p in old_params.values() if p.default is not inspect.Signature.empty),
@@ -631,8 +655,6 @@ class SchemaGenerator:
631
655
 
632
656
  if model in self.concrete_models:
633
657
  return self.concrete_models[model]
634
- else:
635
- wrapper = self._get_wrapper_for_model(model)
636
658
 
637
659
  wrapper = self._get_wrapper_for_model(model)
638
660
  model_copy = wrapper.generate_model_copy(self)
@@ -655,6 +677,8 @@ class SchemaGenerator:
655
677
  return self.model_bundle.enums[model]
656
678
 
657
679
  if lenient_issubclass(model, BaseModel):
680
+ # TODO: My god, what if one of its fields is in our concrete schemas and we don't use it? :O
681
+ # TODO: Add an argument with our concrete schemas for _wrap_pydantic_model
658
682
  wrapper = _wrap_pydantic_model(model)
659
683
  self.model_bundle.schemas[model] = wrapper
660
684
  elif lenient_issubclass(model, Enum):
@@ -977,3 +1001,11 @@ class _EnumWrapper(Generic[_T_ENUM]):
977
1001
  and k not in _DummyEnum.__dict__
978
1002
  and (k not in mro_dict or mro_dict[k] is not v)
979
1003
  }
1004
+
1005
+
1006
+ def _try_eval_type(value: Any, globals: dict[str, Any]) -> Any:
1007
+ new_value, success = pydantic_try_eval_type(value, globals)
1008
+ if success:
1009
+ return new_value
1010
+ else: # pragma: no cover # Can't imagine when this would happen
1011
+ return value
@@ -3,7 +3,7 @@ from dataclasses import dataclass
3
3
  from typing import TYPE_CHECKING, Any, Literal, cast
4
4
 
5
5
  from issubclass import issubclass as lenient_issubclass
6
- from pydantic import BaseModel, Field
6
+ from pydantic import AliasChoices, AliasPath, BaseModel, Field
7
7
  from pydantic._internal._decorators import PydanticDescriptorProxy, unwrap_wrapped_function
8
8
  from pydantic.fields import FieldInfo
9
9
 
@@ -18,58 +18,83 @@ if TYPE_CHECKING:
18
18
 
19
19
  PossibleFieldAttributes = Literal[
20
20
  "default",
21
- "default_factory",
22
21
  "alias",
22
+ "alias_priority",
23
+ "default_factory",
24
+ "validation_alias",
25
+ "serialization_alias",
23
26
  "title",
27
+ "field_title_generator",
24
28
  "description",
29
+ "examples",
25
30
  "exclude",
26
31
  "const",
32
+ "deprecated",
33
+ "frozen",
34
+ "validate_default",
35
+ "repr",
36
+ "init",
37
+ "init_var",
38
+ "kw_only",
39
+ "fail_fast",
27
40
  "gt",
28
41
  "ge",
29
42
  "lt",
30
43
  "le",
31
- "deprecated",
32
- "fail_fast",
33
44
  "strict",
45
+ "coerce_numbers_to_str",
34
46
  "multiple_of",
35
47
  "allow_inf_nan",
36
48
  "max_digits",
37
49
  "decimal_places",
38
50
  "min_length",
39
51
  "max_length",
52
+ "union_mode",
40
53
  "allow_mutation",
41
54
  "pattern",
42
55
  "discriminator",
43
- "repr",
44
56
  ]
45
57
 
46
58
 
59
+ # TODO: Add json_schema_extra as a breaking change in a major version
47
60
  @dataclass(slots=True)
48
61
  class FieldChanges:
49
62
  default: Any
63
+ alias: str | None
50
64
  default_factory: Any
51
- alias: str
52
- title: str
65
+ alias_priority: int | None
66
+ validation_alias: str | AliasPath | AliasChoices | None
67
+ serialization_alias: str | None
68
+ title: str | None
69
+ field_title_generator: Callable[[str, FieldInfo], str] | None
53
70
  description: str
71
+ examples: list[Any] | None
54
72
  exclude: "AbstractSetIntStr | MappingIntStrAny | Any"
55
73
  const: bool
56
74
  deprecated: bool
75
+ frozen: bool | None
76
+ validate_default: bool | None
77
+ repr: bool
78
+ init: bool | None
79
+ init_var: bool | None
80
+ kw_only: bool | None
57
81
  fail_fast: bool
58
82
  gt: float
59
83
  ge: float
60
84
  lt: float
61
85
  le: float
62
86
  strict: bool
87
+ coerce_numbers_to_str: bool | None
63
88
  multiple_of: float
64
89
  allow_inf_nan: bool
65
90
  max_digits: int
66
91
  decimal_places: int
67
92
  min_length: int
68
93
  max_length: int
94
+ union_mode: Literal["smart", "left_to_right"]
69
95
  allow_mutation: bool
70
96
  pattern: str
71
97
  discriminator: str
72
- repr: bool
73
98
 
74
99
 
75
100
  @dataclass(slots=True)
@@ -113,29 +138,41 @@ class AlterFieldInstructionFactory:
113
138
  name: str = Sentinel,
114
139
  type: Any = Sentinel,
115
140
  default: Any = Sentinel,
141
+ alias: str | None = Sentinel,
116
142
  default_factory: Callable = Sentinel,
117
- alias: str = Sentinel,
143
+ alias_priority: int = Sentinel,
144
+ validation_alias: str = Sentinel,
145
+ serialization_alias: str = Sentinel,
118
146
  title: str = Sentinel,
147
+ field_title_generator: Callable[[str, FieldInfo], str] = Sentinel,
119
148
  description: str = Sentinel,
149
+ examples: list[Any] = Sentinel,
120
150
  exclude: "AbstractSetIntStr | MappingIntStrAny | Any" = Sentinel,
121
151
  const: bool = Sentinel,
152
+ deprecated: bool = Sentinel,
153
+ frozen: bool = Sentinel,
154
+ validate_default: bool = Sentinel,
155
+ repr: bool = Sentinel,
156
+ init: bool = Sentinel,
157
+ init_var: bool = Sentinel,
158
+ kw_only: bool = Sentinel,
159
+ fail_fast: bool = Sentinel,
122
160
  gt: float = Sentinel,
123
161
  ge: float = Sentinel,
124
162
  lt: float = Sentinel,
125
163
  le: float = Sentinel,
126
164
  strict: bool = Sentinel,
127
- deprecated: bool = Sentinel,
165
+ coerce_numbers_to_str: bool = Sentinel,
128
166
  multiple_of: float = Sentinel,
129
167
  allow_inf_nan: bool = Sentinel,
130
168
  max_digits: int = Sentinel,
131
169
  decimal_places: int = Sentinel,
132
170
  min_length: int = Sentinel,
133
171
  max_length: int = Sentinel,
172
+ union_mode: Literal["smart", "left_to_right"] = Sentinel,
134
173
  allow_mutation: bool = Sentinel,
135
174
  pattern: str = Sentinel,
136
175
  discriminator: str = Sentinel,
137
- repr: bool = Sentinel,
138
- fail_fast: bool = Sentinel,
139
176
  ) -> FieldHadInstruction:
140
177
  return FieldHadInstruction(
141
178
  schema=self.schema,
@@ -145,28 +182,40 @@ class AlterFieldInstructionFactory:
145
182
  field_changes=FieldChanges(
146
183
  default=default,
147
184
  default_factory=default_factory,
185
+ alias_priority=alias_priority,
148
186
  alias=alias,
187
+ validation_alias=validation_alias,
188
+ serialization_alias=serialization_alias,
149
189
  title=title,
190
+ field_title_generator=field_title_generator,
150
191
  description=description,
192
+ examples=examples,
151
193
  exclude=exclude,
152
194
  const=const,
195
+ deprecated=deprecated,
196
+ frozen=frozen,
197
+ validate_default=validate_default,
198
+ repr=repr,
199
+ init=init,
200
+ init_var=init_var,
201
+ kw_only=kw_only,
202
+ fail_fast=fail_fast,
153
203
  gt=gt,
154
204
  ge=ge,
155
205
  lt=lt,
156
206
  le=le,
157
- deprecated=deprecated,
158
207
  strict=strict,
208
+ coerce_numbers_to_str=coerce_numbers_to_str,
159
209
  multiple_of=multiple_of,
160
210
  allow_inf_nan=allow_inf_nan,
161
211
  max_digits=max_digits,
162
212
  decimal_places=decimal_places,
163
213
  min_length=min_length,
164
214
  max_length=max_length,
215
+ union_mode=union_mode,
165
216
  allow_mutation=allow_mutation,
166
217
  pattern=pattern,
167
218
  discriminator=discriminator,
168
- repr=repr,
169
- fail_fast=fail_fast,
170
219
  ),
171
220
  )
172
221
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cadwyn
3
- Version: 4.5.0
3
+ Version: 4.6.0
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Project-URL: Source code, https://github.com/zmievsa/cadwyn
6
6
  Project-URL: Documentation, https://docs.cadwyn.dev
@@ -4,14 +4,14 @@ cadwyn/_asts.py,sha256=kd6Ngwr8c-uTNx-R-pP48Scf0OdjrTyEeSYe5DLoGqo,5095
4
4
  cadwyn/_importer.py,sha256=QV6HqODCG9K2oL4Vc15fAqL2-plMvUWw_cgaj4Ln4C8,1075
5
5
  cadwyn/_render.py,sha256=LJ-R1TrBgMJpTkJb6pQdRWaMjKyw3R6eTlXXEieqUw0,5466
6
6
  cadwyn/_utils.py,sha256=rlD1SkswtZ1bWgKj6PLYbVaHYkD-NzY4iUcHdPd2Y68,1475
7
- cadwyn/applications.py,sha256=worXUWoexSev0cGJYzXMFBxUgibC1AsM35SYtcV996k,16948
7
+ cadwyn/applications.py,sha256=-MQL8_WWQSvnP1Z3zS7BlVwjrUWUGW9s1xVV1mKha6E,17008
8
8
  cadwyn/changelogs.py,sha256=uveMizeeqNv0JuXza9Rkg0ulDEWyJL24bRxcHkHlwjI,20054
9
9
  cadwyn/exceptions.py,sha256=VlJKRmEGfFTDtHbOWc8kXK4yMi2N172K684Y2UIV8rI,1832
10
10
  cadwyn/middleware.py,sha256=kUZK2dmoricMbv6knPCIHpXEInX2670XIwAj0v_XQxk,3408
11
11
  cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  cadwyn/route_generation.py,sha256=tdIsdDIBY4hVUlTGMh4pTMM92LzxhV9CmGs6J8iAhaw,25152
13
13
  cadwyn/routing.py,sha256=mZRe7ivfTY2qdgrCBO4AHvKQq6Dazf7g_8B6aCrTgN8,7221
14
- cadwyn/schema_generation.py,sha256=OUOcBfIDFviSqIYy0a2EHVWWSh1n2GKbvtr5xuolFgQ,40750
14
+ cadwyn/schema_generation.py,sha256=W3SnBPF4fRK48bXGF-EooJHhkKoQMhzJgP-jC5FP98k,41951
15
15
  cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
17
17
  cadwyn/structure/__init__.py,sha256=Wgvjdq3vfl9Yhe-BkcFGAMi_Co11YOfTmJQqgF5Gzx4,655
@@ -19,10 +19,10 @@ cadwyn/structure/common.py,sha256=GUclfxKLRlFwPjT237fCtLIzdvjvC9gI3acuxBizwbg,41
19
19
  cadwyn/structure/data.py,sha256=uViRW4uOOonXZj90hOlPNk02AIwp0fvDNoF8M5_CEes,7707
20
20
  cadwyn/structure/endpoints.py,sha256=8lrc4xanCt7gat106yYRIQC0TNxzFkLF-urIml_d_X0,5934
21
21
  cadwyn/structure/enums.py,sha256=bZL-iUOUFi9ZYlMZJw-tAix2yrgCp3gH3N2gwO44LUU,1043
22
- cadwyn/structure/schemas.py,sha256=bck4XzCOICVuohh-ZpIv4l57hx3l-f0O23b7w8n2WvA,8215
22
+ cadwyn/structure/schemas.py,sha256=v_wDTn84SgHVDFDlTgoalUzBXpDbT5Hl73Skp0UyGAM,10081
23
23
  cadwyn/structure/versions.py,sha256=L07vdC9d7_h4WKV8TArgZKfgfzB8-M4f62FXZm8o1TM,33232
24
- cadwyn-4.5.0.dist-info/METADATA,sha256=7V9B9KEfVWvWZPDZBCNLgGYMRqvJ1w2-bX69O9z8xmY,4504
25
- cadwyn-4.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
- cadwyn-4.5.0.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
27
- cadwyn-4.5.0.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
28
- cadwyn-4.5.0.dist-info/RECORD,,
24
+ cadwyn-4.6.0.dist-info/METADATA,sha256=KFK2JacLS-rYQju0mqFUk-c1niFrYZa1Kitkj7gOYGw,4504
25
+ cadwyn-4.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
+ cadwyn-4.6.0.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
27
+ cadwyn-4.6.0.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
28
+ cadwyn-4.6.0.dist-info/RECORD,,
File without changes