Skip to content

0.3.0: a field that admits several classes stores its value under a member tag - #23

Merged
trissim merged 1 commit into
mainfrom
feat/family-member-tag
Oct 12, 2026
Merged

trissim merged 1 commit into
mainfrom
feat/family-member-tag

Conversation

@trissim

@trissim trissim commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

The stored form changes for fields whose declared type admits several classes; there is no reader for the old form.

  • to_jsonable writes such a field as {tag: fields} and dataclass_from_mapping reads 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 is AutoRegisterMeta (its registry).
  • The tag is the member's registry key when it is registered (stable across module moves and renames), otherwise the class name. It is derived in one place, class_tag.
  • Unknown tag: ValueError naming the known members. Value outside the declared family, or two members with one tag: TypeError.
  • A type with its own registered projection keeps its whole stored form.
  • to_jsonable now reads the declared field types of each dataclass it encodes; a field type that does not resolve at run time is a TypeError naming 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

…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>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@trissim
trissim merged commit a9428c3 into main Oct 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants