Skip to content

Commit d97f9a3

Browse files
committed
Improve docstrings for _is_primitive_union and _make_converter functions for clarity
1 parent 354337d commit d97f9a3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pyoverkiz/converter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919

2020
def _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:
3135
def _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

0 commit comments

Comments
 (0)