File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919
2020def _is_primitive_union (t : Any ) -> bool :
21- """True for union types containing only JSON-native types and enums (no attrs classes)."""
21+ """True for unions of JSON-native types (e.g. StateType).
22+
23+ Excludes unions containing attrs classes (e.g. Definition | None) since those
24+ need actual structuring by cattrs.
25+ """
2226 origin = get_origin (t )
2327 if origin is not Union and not isinstance (t , types .UnionType ):
2428 return False
@@ -31,7 +35,8 @@ def _is_primitive_union(t: Any) -> bool:
3135def _make_converter () -> cattrs .Converter :
3236 c = cattrs .Converter ()
3337
34- # Primitive unions like StateType (str | int | float | … | None): pass through as-is
38+ # JSON-native unions like StateType (str | int | float | … | None) are already the
39+ # correct Python type after JSON parsing — tell cattrs to pass them through as-is.
3540 c .register_structure_hook_func (_is_primitive_union , lambda v , _ : v )
3641
3742 # Enums: call the constructor so UnknownEnumMixin._missing_ can handle unknown values
You can’t perform that action at this time.
0 commit comments