feat(data): Pydantic-aware Mapper + nested/collection recursion + @mapping decorator (v26.06.24)#50
Merged
Merged
Conversation
…mapping decorator + bump v26.06.24 Spring-parity work, wave 3 (MapStruct). Extended the existing pyfly.data.Mapper (runtime/reflection, not Java codegen): - Pydantic-aware: shallow extraction keeps nested models as live instances (was dataclasses.asdict deep-flatten, which broke nested dests); pydantic read via model_fields + constructed through the validating constructor. - Nested-model recursion: a dest field typed as another mappable model is mapped recursively. - Collection recursion: list/tuple/set dest fields of a mappable element type map element-wise. - Declarative @mapping(Source, Dest, rename=, transform=, exclude=) decorator registering on a module-level default_mapper (exported as pyfly.data.mapping / default_mapper). Existing Mapper API unchanged/back-compatible. Tests: tests/data/test_mapper_nested.py (4), existing test_mapper{,_projection}.py (16) green. Gates: mypy --strict (609), ruff + format, full suite 3746 passed.
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.
Summary
Wave 3 — the MapStruct ask. Per the analysis, extended the existing
pyfly.data.Mapper(runtime/reflection) rather than cloning MapStruct's compile-time codegen / generated*Implclasses / expression DSL.dataclasses.asdictdeep-flattened nested models to dicts, breaking nested destinations); Pydantic read viamodel_fields, constructed through the validating constructor.list/tuple/setfields of a mappable element type map element-wise.@mapping—@mapping(Source, Dest, rename=..., transform=..., exclude=...)registers on a module-leveldefault_mapper, config next to the types. Exported aspyfly.data.mapping/default_mapper.Existing
MapperAPI (add_mapping/map/map_list/projections) unchanged & back-compatible.Tests
tests/data/test_mapper_nested.py(4: nested recursion, collection recursion, pydantic rename/transform, declarative decorator) + existing 16 mapper tests green.Gates
mypy --strict(609) ✓ ·ruff+ruff format✓ · full suite 3746 passed, 1 skipped.Bumps
v26.06.23 → v26.06.24. Wave 4 (RFC 7807, multi-datasource, SpEL, Testcontainers) to follow.Records/Lombok: no code — covered idiomatically by frozen dataclasses / Pydantic, as established.