fix: handle both pydantic version 1 and 2 to support python 3.14 #101
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.
Description
As of python 3.14, pydantic>=2.0.0 does not work with the pydantic.v1 namespace. While trying to fix this same issue for spaCy (explosion/spaCy#13895), I ran into this library also throwing errors from the old pydantic version.
To fix this without a major version upgrade, I added some conditional model definitions where necessary. I think this approach is fairly safe since pydantic appears to only be used internally to validate configuration so you shouldn't have to worry about any other packages calling deprecated pydantic model functions. I saw a similar pattern from one of y'alls other repos here: explosion/confection#31
The main pydantic breaking changes impacting this repo are pretty straightforward, just changing root_validator to model_validator, altering the model configration to use a dictionary, and swapping to pattern over regex for string fields.
I've also updated CI to test against python 3.14.
On my own, I've run tests against back to python 3.8 with
pydantic==1.7.4.Types of change
Bug fix - the package is broken on python 3.14 and breaks any upstream packages that attempt to use python 3.14.
Checklist