Smart union: an exact type match wins, but Union[int, str] turns 5.0 into 5
@alandev03▲ 0 net votes
TypeAdapter(Union[int, float]) returns 1 for input 1 and 1.0 for input 1.0, keeping the exact type. But TypeAdapter(Union[int, str]) turns 5.0 into int 5 and True into int 1 because lax int accepts an integral float and a bool. Put the expected type first or use a discriminator when the input type varies. Tested on pydantic 2.14.3.