Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compatibility for pydantic v2 #224

Merged
merged 2 commits into from
Dec 23, 2023

Conversation

gotmax23
Copy link
Collaborator

@gotmax23 gotmax23 commented Dec 4, 2023

This uses the pydantic.v1 compat module (well really, it's just an
in-tree copy of the latest pydantic v1 release) so we can also support
pydantic v2. Major changes to root models make it infeasible to support
pydantic v2 natively without dropping support for v1.

The _pydantic_compat module simplifies imports of the pydantic.v1
compat module with pydantic v2. The pydantic.v1 compat module is always
used when type checking. We have to force one of them when type
checking, as type checkers cannot understand try-except imports.


See ansible-community/antsibull-core#125.

@gotmax23 gotmax23 marked this pull request as draft December 4, 2023 23:45
@gotmax23 gotmax23 force-pushed the pydanticv2-compat branch 4 times, most recently from 4960878 to 87da1f6 Compare December 5, 2023 01:03
@gotmax23 gotmax23 force-pushed the pydanticv2-compat branch 3 times, most recently from fadd86d to cdd9ea3 Compare December 23, 2023 04:58
This uses the `pydantic.v1` compat module (well really, it's just an
in-tree copy of the latest pydantic v1 release) so we can also support
pydantic v2. Major changes to root models make it infeasible to support
pydantic v2 natively without dropping support for v1.

The `_pydantic_compat` module simplifies imports of the `pydantic.v1`
compat module with pydantic v2. The pydantic.v1 compat module is always
used when type checking. We have to force one of them when type
checking, as type checkers cannot understand `try-except` imports.
pyre does not understand our _pydantic_compat module and spews errors.
@gotmax23 gotmax23 changed the title [DNM] Pydantic v2 compat POC add compatibility for pydantic v2 Dec 23, 2023
@gotmax23 gotmax23 marked this pull request as ready for review December 23, 2023 05:15
@gotmax23
Copy link
Collaborator Author

Ready for review

@felixfontein felixfontein merged commit ab8b373 into ansible-community:main Dec 23, 2023
11 of 12 checks passed
@felixfontein
Copy link
Collaborator

@gotmax23 thanks for this one as well!

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