modmex 1.2.0__tar.gz → 1.2.2__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.
- {modmex-1.2.0 → modmex-1.2.2}/PKG-INFO +1 -1
- {modmex-1.2.0 → modmex-1.2.2}/modmex/base_model.py +4 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/validation.py +27 -0
- {modmex-1.2.0 → modmex-1.2.2}/pyproject.toml +1 -1
- {modmex-1.2.0 → modmex-1.2.2}/LICENSE +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/README.md +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/__init__.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/__init__.pyi +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/base_model.pyi +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/datetime_parser.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/errors.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/fields.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/model_plans.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/py.typed +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/rust_backend.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/serialization.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex/type_resolution.py +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/Cargo.lock +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/Cargo.toml +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/src/coerce.rs +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/src/lib.rs +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/src/model_core.rs +0 -0
- {modmex-1.2.0 → modmex-1.2.2}/modmex-core/src/types.rs +0 -0
|
@@ -628,6 +628,10 @@ class _JsonSchemaBuilder:
|
|
|
628
628
|
def _type_schema(self, annotation: Any, field_name: str) -> dict[str, Any]:
|
|
629
629
|
if annotation is Any:
|
|
630
630
|
return {}
|
|
631
|
+
if annotation is list:
|
|
632
|
+
return {"type": "array"}
|
|
633
|
+
if annotation is dict:
|
|
634
|
+
return {"type": "object", "additionalProperties": {}}
|
|
631
635
|
json_type = _JSON_TYPE_BY_PYTHON_TYPE.get(annotation)
|
|
632
636
|
if json_type is not None:
|
|
633
637
|
return {"type": json_type}
|
|
@@ -35,6 +35,25 @@ def is_none_type(tp: Any) -> bool:
|
|
|
35
35
|
return tp in _NONE_TYPES
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
def _exact_union_type(union_types: tuple[Any, ...], value: Any) -> Any | None:
|
|
39
|
+
"""Return an already-matching union branch before permissive coercion.
|
|
40
|
+
|
|
41
|
+
Union validation historically tried branches in declaration order. That
|
|
42
|
+
made ``str | int`` turn an integer into a string before the integer branch
|
|
43
|
+
could be considered. Preserve values whose runtime type already matches
|
|
44
|
+
a branch, while retaining the existing coercive fallback for values that
|
|
45
|
+
do not match any branch exactly.
|
|
46
|
+
"""
|
|
47
|
+
for item_type in union_types:
|
|
48
|
+
if not isinstance(item_type, type):
|
|
49
|
+
continue
|
|
50
|
+
if item_type is int and isinstance(value, bool):
|
|
51
|
+
continue
|
|
52
|
+
if isinstance(value, item_type):
|
|
53
|
+
return item_type
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
38
57
|
def str_validator(value: Any) -> str:
|
|
39
58
|
if isinstance(value, str):
|
|
40
59
|
return value
|
|
@@ -315,6 +334,10 @@ def _validate_union(expected_type: Any, value: Any, strict: bool, globalns: Glob
|
|
|
315
334
|
if value is None and any(is_none_type(item_type) for item_type in union_types):
|
|
316
335
|
return None
|
|
317
336
|
|
|
337
|
+
exact_type = _exact_union_type(union_types, value)
|
|
338
|
+
if exact_type is not None:
|
|
339
|
+
return value
|
|
340
|
+
|
|
318
341
|
errors: list[dict[str, Any]] = []
|
|
319
342
|
for item_type in union_types:
|
|
320
343
|
try:
|
|
@@ -452,6 +475,10 @@ def _compile_validator(expected_type: Any, strict: bool, globalns: GlobalNS_T) -
|
|
|
452
475
|
if value is None and accepts_none:
|
|
453
476
|
return None
|
|
454
477
|
|
|
478
|
+
exact_type = _exact_union_type(union_types, value)
|
|
479
|
+
if exact_type is not None:
|
|
480
|
+
return value
|
|
481
|
+
|
|
455
482
|
errors: list[dict[str, Any]] = []
|
|
456
483
|
for item_validator in item_validators:
|
|
457
484
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|