Add DataclassSerializable mixin for @dataclass subclasses#13
Merged
Conversation
Resolves #11. Provides a narrow mixin that gives @dataclass-decorated classes the `to_dict` / `from_dict` / `to_json` / `from_json` API without overriding the `__init__` / `__eq__` / `__repr__` / `__hash__` that `@dataclass` already generates. Wire format is identical to `Serializable`: `to_serializable_repr` dispatches on `obj.to_dict()`, so mixed codebases (some classes still on `Serializable`, some migrated to `DataclassSerializable`) round-trip JSON cleanly. Pickle routes through the same envelope via `__reduce__`. Includes the `_SERIALIZABLE_KEYWORD_ALIASES` escape hatch so legacy field names can be renamed or dropped across releases, mirroring the same mechanism on `Serializable`. Bumps version to 1.1.0 — new public API, no breaking changes.
Coverage Report for CI Build 24681331550Coverage increased (+1.4%) to 89.778%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
…t, README - Fix Tagged.tag annotation: LegacyTag -> LegacyTag | None to match the None default. - Add test_frozen_dataclass_pickle_roundtrip covering __reduce__ on a frozen dataclass (cls(**kwargs) must work even with __setattr__ disabled). Promoted FrozenPoint to module level so pickle can look it up. - Add test_keyword_aliases_inherited_from_parent to confirm alias dicts declared on a parent class fire for child loads — migrations can live on a shared base without every subclass restating them. - README: new section documenting DataclassSerializable, including usage snippet and interop notes for vaxrank/pyensembl/varcode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #11 (requested by vaxrank).
Summary
DataclassSerializablemixin for@dataclass-decorated subclasses: suppliesto_dict/from_dict/to_json/from_jsonwithout overriding the__init__/__eq__/__repr__/__hash__that@dataclassgenerates, so migrated classes get clean dataclass-native equality and repr.Serializable(both dispatch throughto_serializable_repr→obj.to_dict()), so mixed codebases round-trip JSON cleanly — verified intest_interop_with_legacy_serializable._SERIALIZABLE_KEYWORD_ALIASESmigration hook (rename or drop legacy field names).__reduce__.Test plan
./lint.sh(ruff check + ruff format --check)./test.sh— 40 passed locally (13 new tests,dataclass_serializable.pyat 100% coverage)