/home/lane/Code/which2rent/venv/bin/python /home/lane/Code/which2rent/nest.py
Traceback (most recent call last):
File "/home/lane/Code/which2rent/nest.py", line 33, in <module>
print(dacite.from_dict(C, testcase))
File "/home/lane/Code/which2rent/venv/lib/python3.8/site-packages/dacite/core.py", line 65, in from_dict
raise WrongTypeError(field_path=field.name, field_type=field.type, value=value)
dacite.exceptions.WrongTypeError: wrong value type for field "aa" - should be "dataclasses.InitVar[typing.List[__main__.A]]" instead of value "[{'a': 1}, {'a': 2}]" of type "list"
B(aa=[A(a=1), A(a=2)])
env
Python: 3.8
dancite: 1.5.1
testcase
import dataclasses
from typing import *
import dacite
@dataclasses.dataclass
class A:
a: int
@dataclasses.dataclass
class B:
aa: List[A]
@dataclasses.dataclass
class C:
aa: dataclasses.InitVar[List[A]]
real_aa: List[A] = dataclasses.field(init=False)
def __post_init__(self, aa: List[A]):
self.real_aa = [A(a=a.a+1) for a in aa]
testcase = {
'aa': [
{'a': 1},
{'a': 2}
]
}
print(dacite.from_dict(B, testcase)) # working
print(dacite.from_dict(C, testcase)) # not working
traceback
env
testcase