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
Return value of custom type hook is discarded when decoding generic type in union.
To Reproduce
In the following example, a generic dataclass Foo[T] is defined and used as a field in another dataclass Bar. In the example, only the type Foo[int] is actually used and for that type, a custom type hook is defined that decodes a value from a JSON int:
I.e. the field foo has been set to the original int value from the data instead of the value returned by _read_int_foo(). This only happens when check_types is set to False (otherwise a UnionMatchError is raised).
Describe the bug
Return value of custom type hook is discarded when decoding generic type in union.
To Reproduce
In the following example, a generic dataclass
Foo[T]
is defined and used as a field in another dataclassBar
. In the example, only the typeFoo[int]
is actually used and for that type, a custom type hook is defined that decodes a value from a JSON int:Running this prints the following:
I.e. the field
foo
has been set to the original int value from the data instead of the value returned by_read_int_foo()
. This only happens whencheck_types
is set toFalse
(otherwise aUnionMatchError
is raised).Expected behavior
IMHO, the returned value should be used:
Environment
The text was updated successfully, but these errors were encountered: