From 0fdb6f891b1bf6b0cde78265d7b9d2c82ca8542f Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Sun, 11 Sep 2022 06:15:03 +0200 Subject: [PATCH] dataclass: handle non-DataClass Munches properly --- dataclass.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dataclass.py b/dataclass.py index 2b3bb13..32352d7 100644 --- a/dataclass.py +++ b/dataclass.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass from munch import Munch from typing import Optional, Union, Mapping, Any, get_type_hints, get_origin, get_args, Iterable @@ -44,7 +46,8 @@ class DataClass(Munch): 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] + kwargs = {'validate': validate} if issubclass(target_class, DataClass) else {} + value = target_class.fromDict(value, **kwargs) # type:ignore[attr-defined] # handle numerics elif set(_classes).intersection([int, float]) and isinstance(value, str) and str not in _classes: parsed_number = None