mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
dataclass: DataClass.tranform(): handle Optional dict/Munch items
This commit is contained in:
parent
adcdf38c14
commit
7b7caf3f37
1 changed files with 6 additions and 4 deletions
|
@ -34,12 +34,14 @@ class DataClass(Munch):
|
|||
type_hints = cls._type_hints
|
||||
if key in type_hints:
|
||||
_classes = tuple[type](resolve_type_hint(type_hints[key]))
|
||||
optional = type(None) in _classes
|
||||
if issubclass(_classes[0], dict):
|
||||
assert isinstance(value, dict)
|
||||
assert isinstance(value, dict) or optional
|
||||
target_class = _classes[0]
|
||||
if target_class is dict:
|
||||
target_class = Munch
|
||||
if not isinstance(value, target_class):
|
||||
if not (optional and value is None):
|
||||
assert issubclass(target_class, Munch)
|
||||
# despite the above assert, mypy doesn't seem to understand target_class is a Munch here
|
||||
value = target_class.fromDict(value, validate=validate) # type:ignore[attr-defined]
|
||||
|
|
Loading…
Add table
Reference in a new issue