Serialize a dataclass schema to a field list - #315
Draft
farmio wants to merge 1 commit into
Draft
Conversation
to_field_list unwrapped a Schema to its node, which for a dataclass schema is the validate-then-construct pair rather than the mapping, so it raised while the equivalent TypedDict schema serialized fine. Unwrap to the mapping the construction step consumes. Nested mappings still raise, matching voluptuous-serialize, which has no field-list shape for them either.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #315 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 45 45
Lines 6590 6596 +6
Branches 1220 1221 +1
=========================================
+ Hits 6590 6596 +6 ☔ View full report in Codecov by Harness. |
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.
Breaking change
None. A dataclass schema raised before, so nothing that worked changes. Nested
mappings still raise.
Proposed change
to_field_listunwrapped aSchemato its node. For a dataclass schema that nodeis the validate-then-construct pair, not the mapping, so it raised while the
equivalent
TypedDictSchemaserialized fine.constructed_mapping()indataclass_schema.pyreturns the mapping aconstructing schema validates, and
to_field_listuses it before serializing.Putting the check there keeps the shape of the pair private to the module that
builds it, rather than teaching the codec how a dataclass schema is assembled.
Nested mappings are left alone: voluptuous-serialize raises for those too, and a
test now pins both sides of that.
One open question for you. I added
constructed_mappingas a module-levelfunction because
create_dataclass_schemareturns a plainSchema, so a methodor property on
DataclassSchemawould not cover the functional builder. If youwould rather not grow the module surface, the alternative is a shape check inside
the codec, which I liked less.
fixes #313
Type of change
Additional information
Checklist
uv run --no-sync just testpasses locally.uv run --no-sync just lintpasses.uv run --no-sync just typecheckpasses.