Skip to content

feat: Pydantic v2 upgrade#388

Open
lmmx wants to merge 1 commit intoantonagestam:mainfrom
lmmx:pydantic-v2-migration
Open

feat: Pydantic v2 upgrade#388
lmmx wants to merge 1 commit intoantonagestam:mainfrom
lmmx:pydantic-v2-migration

Conversation

@lmmx
Copy link
Copy Markdown

@lmmx lmmx commented Jan 19, 2026

I discussed the approach a little here #286 (comment)

  • I fixed what I think was an incidental bug in int vs. float handling, added exceptions for ABCs and Protocols, and a fallback to an Any-typed schema (which importantly we never see in the tests, it isn't expected to fire in normal usage).
  • I updated the way the validator is called, fairly straightforward.
  • I moved the MissingDependency machinery inside the call site (this seemed necessary, and after this the tests worked in both with/without dateutil)
  • I updated the test fixtures to the v2 (improved!) JSONSchemas, they are only v lightly changed from the old ones.
  • Other trivial changes in Pydantic v2 API

Conditional imports

This PR introduces a hard import on pydantic and pydantic core in 4 modules ({_base,sized,schema,negated}.py).

  • The simplest way to solve this is a conditional import that simply fails, which I did.
  • Then it's best for performance to gate any imports not actually used (besides for type hints) under TYPE_CHECKING, which I did too. (For instance, someone with pydantic installed but not using the pydantic parts of this library shouldn't "pay" for the time to import pydantic)
  • I also introduced a small helper utility func to raise the MissingDependency error in a nice way, without having to repeat it everywhere

Checklist

  • Runs with and without Pydantic (conditional imports work)
  • Tests pass with make test
  • mypy check passes
  • Docs build OK (bumped to 3.12)
  • Goose checks pass with goose run --select=all
  • Docs updated (README + Pydantic support docs site page)

@lmmx lmmx mentioned this pull request Jan 19, 2026
@lmmx lmmx force-pushed the pydantic-v2-migration branch from b54f2e1 to 0201708 Compare January 19, 2026 21:52
@lmmx

This comment was marked as resolved.

@lmmx lmmx force-pushed the pydantic-v2-migration branch 2 times, most recently from 29a6af7 to f8d1697 Compare January 19, 2026 23:28
@lmmx lmmx force-pushed the pydantic-v2-migration branch from f8d1697 to c07fe39 Compare January 19, 2026 23:36
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.

Support Pydantic V2

1 participant