Closed LTluttmann closed 1 year ago
Hey @LTluttmann , thanks for posting.
Hmm, the annotation says it's a float
, so it's expected for the serialization to fail if the value is None
. Perhaps you could try with float | None
or Optional[float]
as an annotation? (Those should work correctly)
oh wow, thanks! Optional[float] is exactly what I was looking for and works just fine! I will close the issue then
Is your feature request related to a problem? Please describe. Currently, when reading a serialized dataclass which contains None values, an error occurs during decoding the serialized data.
To reproduce
This raises the following error: "float() argument must be a string or a real number, not 'NoneType'".
Describe the solution you'd like The error is raised in the decode_field function, here. One solution would be to insert an if-else statement like so:
However, I don't know if this might introduce problems elsewhere or with other edge cases. Tests are still working, though
Describe alternatives you've considered Maybe, there is also a workaround I'm not aware of