You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a dataclass with Union comprised of int/float causes the value to be cast to whichever appears first in the Union definition. Looking at the pack_union method, the output makes sense, but wondering if special cases should be added to preserve int/float types.
Default converters for int and float types on serialization are int and float functions respectively. It has its roots in how Union types are currently processed. Imagine that you have Union[int, <another_dataclass>]. If int values were passing as is, then we would be passing <another_dataclass> values as is because "passing through" strategy appears first. I have plans to rework Union types and get rid of explicit converters for int, float types but before that you can use pass_through helper:
Description
Using a dataclass with Union comprised of int/float causes the value to be cast to whichever appears first in the Union definition. Looking at the pack_union method, the output makes sense, but wondering if special cases should be added to preserve int/float types.
What I Did
Output:
{'val1': 3.0, 'val2': 3}
The text was updated successfully, but these errors were encountered: