Repository navigation
0.3.0: a field that admits several classes stores its value under a member tag - #23
Merged
Merged
Conversation
…ember tag
A dataclass field whose declared type is a union of dataclasses, an abstract
dataclass or a registered class is written as {tag: fields} and read back by
the tag. The tag is the member's registry key when it is registered, otherwise
its class name. Before, a union member was guessed from the fields present:
two members with the same fields were ambiguous and the stored value did not
say which class it was. An unknown tag is an error naming the known members.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The stored form changes for fields whose declared type admits several classes; there is no reader for the old form.
to_jsonablewrites such a field as{tag: fields}anddataclass_from_mappingreads the class from the tag. A family (MemberFamily.declared_by) is a union with two or more dataclass members, an abstract dataclass (its concrete subclasses), or a class whose metaclass isAutoRegisterMeta(its registry).class_tag.ValueErrornaming the known members. Value outside the declared family, or two members with one tag:TypeError.to_jsonablenow reads the declared field types of each dataclass it encodes; a field type that does not resolve at run time is aTypeErrornaming the class.Tests: round trip for each member of each kind of family, members with identical fields, containers and optional fields, unknown tag, untagged data refused. 191 pass on Python 3.10, 3.12 and 3.13.
Dependants whose upper bound excludes 0.3.0: ObjectState, formbridge, pyqt-reactive, zmqruntime (all
<0.3).🤖 Generated with Claude Code