Currently, we have to wrap int and float values on serialization with int(...) and float(...). This is used as a hack for poor union serialization logic which is based on applying an encoding operation for each type in the list until we get the first result without errors. If we have a value of type Union[int, DataClassA] then without applying int(value) (which will obviously fail on instances of DataClassA) we would pass instances of DataClassA as is because int is on the first place.
In this PR union serialization logic is changed so that we check the type of a value with pass-through strategy before returning it as is. It allows us to remove a hack for int and float and not try to perform encoding operations that are known to fail.
Currently, we have to wrap
int
andfloat
values on serialization withint(...)
andfloat(...)
. This is used as a hack for poor union serialization logic which is based on applying an encoding operation for each type in the list until we get the first result without errors. If we have a value of typeUnion[int, DataClassA]
then without applyingint(value)
(which will obviously fail on instances ofDataClassA
) we would pass instances ofDataClassA
as is becauseint
is on the first place.In this PR union serialization logic is changed so that we check the type of a value with pass-through strategy before returning it as is. It allows us to remove a hack for
int
andfloat
and not try to perform encoding operations that are known to fail.This pull request fixes the following issues: