Repository navigation
Conversation
…tributes Fixes finos#58 Signed-off-by: Walter Hawkins <wdhawkins46@gmail.com>
This branch has not been deployed
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.
Fixes #58
Summary
Preserves concrete Rune subtype instances, subtype-only fields, and
@typediscriminators when assigned to or deserialized into attributes declared with a parentBaseDataClasstype (both scalar and list attributes):BaseDataClass.__init_subclass__/_wrap_polymorphic_validators):WrapValidatorto fields declared with aBaseDataClasstype annotation so that when a concrete subclass instance (e.g.Childwhereclass Child(Parent)) or a dict carrying"@type"is supplied for a parent-typed attribute (orlist[Parent]attribute), the concrete subclass instance is preserved rather than coerced/truncated into a plainParentinstance.BaseDataClass.validate_model):BaseDataClass._serialize_polymorphic_fields&_serialize_polymorphic_value):model_dump()and injects"@type": orig_val._fqrtn()whenever the runtime value is a strict subclass of the declared field type (isinstance(orig_val, expected_cls) and type(orig_val) is not expected_cls).BaseDataClass.rune_deserialize):"@type"discriminators via_resolve_subtypes()beforemodel_validate()so round-trippingHolder(item=Child(...)).rune_serialize()throughHolder.rune_deserialize(...)reconstructs the exactChildsubtype instance.Verification
test/test_polymorphic_subtypes.pycovering scalar and list parent-typed attributes, subtype-specific fields,@typeemission, andrune_deserializereconstruction.pytest:359 passed, 20 skipped.