Closed kacirekj closed 3 years ago
Hi @kacirekj - thank you for using dacite
.
No, I can not fix it in dacite
because:
1) MyPy
behaves in the same way, it raises:
error: Incompatible types in assignment (expression has type "None", variable has type "MyObject")
2) PEP 484 says:
A past version of this PEP allowed type checkers to assume an optional type when the default value is None (...) This is no longer the recommended behavior. Type checkers should move towards requiring the optional type to be made explicit.
I think that dacite
should be as close as possible to MyPy
and PEP484 when it deals with types.
When I have dataclass:
Then I have defined that myObject is not optional and must be filled in.
When I have dataclass:
Then I have already defined that field myObject is optional and may or may not be filled in.
However default behavior of dacite is to throw this error:
This behavior is nonsense and lead to this redundant and ugly definition:
Can it be fixed?