Skip to content

Fix #66: dataclass from Generic now serializes#78

Merged
NiklasRosenstein merged 7 commits intodevelopfrom
deserialize-generic
Mar 25, 2026
Merged

Fix #66: dataclass from Generic now serializes#78
NiklasRosenstein merged 7 commits intodevelopfrom
deserialize-generic

Conversation

@NiklasRosenstein
Copy link
Copy Markdown
Owner

Continuation of #68 (which was accidentally closed).

Summary

  • When a dataclass inherits from a Generic[T] without parameterizing it (e.g. class B(A) instead of class B(A[T])), serialization/deserialization was dropping the parent's fields.
  • Root cause: hint.bases or hint.type.__bases__ short-circuits — hint.bases contains Generic[T] (not the actual parent), so __bases__ was never consulted.
  • Fix: iterate both (*hint.bases, *hint.type.__bases__) with deduplication via a seen set.

Changes

  • databind/core/schema.py: iterate both base sources with dedup
  • databind/core/tests/schema_test.py: schema-level regression test
  • databind/json/tests/converters_test.py: serialize + deserialize regression test
  • .changelog/_unreleased.toml: changelog entry

Original author: @rhaps0dy

🤖 Generated with Claude Code

rhaps0dy and others added 7 commits May 9, 2024 22:09
Co-authored-by: Niklas Rosenstein <rosensteinniklas@gmail.com>
Adds a `seen` set to avoid processing the same base type twice when
iterating both hint.bases and hint.type.__bases__.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NiklasRosenstein NiklasRosenstein merged commit 00db8a1 into develop Mar 25, 2026
8 checks passed
@NiklasRosenstein NiklasRosenstein deleted the deserialize-generic branch March 25, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants