Closed Garrett-R closed 4 years ago
This is quite similar to Issue #62, only different being that I've now added an extra Optional:
Optional
import dataclasses from typing import Optional import dacite @dataclasses.dataclass class Person: height: Optional[float] = 160 person = Person() person_dict = dataclasses.asdict(person) new_person_1 = dacite.from_dict(data_class=Person, data=person_dict)
On the latest version of Dacite (v1.2.0 ‒ 9c311b1), executing this yields:
WrongTypeError: wrong type for field "height" - should be "typing.Union[float, NoneType]" instead of "int"
Changing Optional[float] to be just float will make it work again. This seems to be a bug since Optional[float] should also work.
Optional[float]
float
@Garrett-R thank you for reporting this issue :)
You have right - it's a bug. Fixed and deployed to PyPI. Please check the newest version (1.2.1).
Woohoo! Thanks!!
This is quite similar to Issue #62, only different being that I've now added an extra
Optional
:On the latest version of Dacite (v1.2.0 ‒ 9c311b1), executing this yields:
Changing
Optional[float]
to be justfloat
will make it work again. This seems to be a bug sinceOptional[float]
should also work.