dacite
dacite copied to clipboard
Regression with nested classes
Describe the bug
Dacite failes to recognize a nested class structure involving tuples and lists.
To Reproduce
from typing import List, Tuple
from dataclasses import dataclass
from dacite import from_dict, Config
@dataclass
class A:
i: List[str]
t: str
@dataclass
class B:
m: Tuple[str, A]
assert from_dict(
data_class=B,
data={"m": ["a", {"i": [], "t": "foo"}]},
config=Config(cast=[tuple])
) == B(m=('a', A(i=[], t='foo')))
Running the code yields:
File ".venv/lib/python3.10/site-packages/dacite/core.py", line 69, in from_dict
raise WrongTypeError(field_path=field.name, field_type=field_type, value=value)
dacite.exceptions.WrongTypeError: wrong value type for field "m" - should be "Tuple" instead of value "('a', {'i': [], 't': 'foo'})" of type "tuple"
Expected behavior No errors Environment
- Python version: 3.10.3
-
daciteversion: 1.8.0
Additional context The code works just fine with dacite 1.6.0