Skip to content

Take DiscriminatedUnion and Shared from pydantic-addons - #32

Merged
nickyoung-github merged 1 commit into
masterfrom
feature/pydantic-addons
Nov 30, 2026
Merged

nickyoung-github merged 1 commit into
masterfrom
feature/pydantic-addons

Conversation

@nickyoung-github

Copy link
Copy Markdown
Owner

DiscriminatedUnion and Shared are now those of pydantic-addons 1.0.0, which this depends on and which has no dependencies of its own. Nothing which imports them from dataclass_native changes.

What changes

  • types.py: imports the two annotations and their markers from pydantic-addons, in place of defining them.
  • pydantic and this read each other's DiscriminatedUnion. pydantic-addons tells pydantic to write one as {"t": tag, "v": value}, by the same tags. So that caveat is gone from JSON_FORMAT.md.
  • Tags agree:
    • @native(tag=...) gives the class's tag to pydantic-addons too.
    • The sizes of int and float, and NaiveDatetime, say theirs by a __tag__: int8, float32, naivedatetime.
  • A new dependency: pydantic-addons>=1.0.0. pydantic itself is still optional.

Tested

  • The whole suite, in every mode: 1,349 passed.
  • New: that the tag of each kind of type is the one pydantic-addons gives, and that pydantic writes and reads a union of sized numbers as this does.
  • test_pydantic_reads_and_writes_classes now has classes with a DiscriminatedUnion: of a class, of an int, of Shared classes with one of a tag of its own, of a NaiveDatetime and of a Decimal.

…antic writes a DiscriminatedUnion as this does
@nickyoung-github
nickyoung-github merged commit 2ddf2da into master Nov 30, 2026
10 of 12 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.

1 participant