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
importdataclassesfromtypingimportGeneric, TypeVarimportdatabind.jsonT=TypeVar("T")
@dataclasses.dataclassclassA(Generic[T]):
a_field: int@dataclasses.dataclassclassB(A):
b_field: strb=B(2, "hi")
out=databind.json.get_object_mapper().serialize(b, B)
print(out) # prints `{'b_field': 'hi'}`, which is wrong.
I've traced this to this line, which adds to the queue base in (hint.bases or hint.type.__bases__).
When T is uninstantiated, the former is non-empty, so the base dataclasses that come the normal way don't get added.
I don't fully understand this code but I think the fix is:
for base in (*hint.bases, *hint.type.__bases__)
to make sure we iterate over everything.
The text was updated successfully, but these errors were encountered:
rhaps0dy
added a commit
to AlignmentResearch/train-learned-planner
that referenced
this issue
May 5, 2024
rhaps0dy
changed the title
Fields fromdataclasses that are Generic with unspecified TypeVars don't get serialized
Fields from dataclasses that are Generic with unspecified TypeVars don't get serialized
May 5, 2024
Here's a minimal reproduction:
I've traced this to this line, which adds to the queue
base in (hint.bases or hint.type.__bases__)
.When
T
is uninstantiated, the former is non-empty, so the base dataclasses that come the normal way don't get added.I don't fully understand this code but I think the fix is:
for base in (*hint.bases, *hint.type.__bases__)
to make sure we iterate over everything.
The text was updated successfully, but these errors were encountered: