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
Expected behaviour: When (de)serializing a dataclass that subclasses from Generic[T] and it has a member that uses T, we should be able to handle the member annotated with T gracefully when a concrete type is given.
Actual behaviour: Databind does not understand the concrete type for a type variable and fails at trying to (de)serialize the field when a concrete type A is given but the type at that position is TypeHint(~T).
Steps to reproduce:
fromdataclassesimportdataclassfromtypingimportGeneric, TypeVarfromdatabind.jsonimportdump, loadT=TypeVar("T")
@dataclassclassBox(Generic[T]):
value: Tprint(dump(Box(42), Box[int])) # no serializer for `TypeHint(~T)` ...print(load({"value": 42}, Box[int])) # no deserializer for `TypeHint(~T)` ...
Results in
databind.core.converter.NoMatchingConverter: no serializer for `TypeHint(~T)` and payload of type `int`
Trace:
$: TypeHint(__main__.Box[int])
.value: TypeHint(~T)
The text was updated successfully, but these errors were encountered:
Python 3.10. Yeah, I agree there should be a test case.
Zooming out, have you considered using Hypothesis (https://hypothesis.readthedocs.io/en/latest/) to test python-databind? The usecase here is perfect: write a test-case-generator for types and instances, and then apply it to a round-trip test. Then apply more computation and find bugs.
Expected behaviour: When (de)serializing a dataclass that subclasses from
Generic[T]
and it has a member that usesT
, we should be able to handle the member annotated withT
gracefully when a concrete type is given.Actual behaviour: Databind does not understand the concrete type for a type variable and fails at trying to (de)serialize the field when a concrete type
A
is given but the type at that position isTypeHint(~T)
.Steps to reproduce:
Results in
The text was updated successfully, but these errors were encountered: