-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Pydantic v2 Package Shim Compatibility (#55)
* Implements `compatibility` subpackage for easier version compatibility maintenance * Adds Pydantic v1 / Pydantic v2 compatibility via shim * Adds Pydantic v1 / Pydantic v2 to testing CI matrix * Updates examples and adds compatibility notice
- Loading branch information
Showing
31 changed files
with
86 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
|
||
# Third-Party | ||
import pydantic | ||
import pydantic.v1 as pydantic | ||
import pydantic_argparse | ||
|
||
# Typing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
|
||
# Third-Party | ||
import pydantic | ||
import pydantic.v1 as pydantic | ||
import pydantic_argparse | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ authors = [{ name = "Hayden Richards", email = "[email protected]" }] | |
readme = "README.md" | ||
license = { file = "LICENSE" } | ||
requires-python = ">=3.8" | ||
dependencies = ["pydantic<2"] | ||
dependencies = ["pydantic"] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
'Programming Language :: Python', | ||
|
@@ -102,7 +102,7 @@ warn_return_any = true | |
warn_unused_ignores = true | ||
no_implicit_optional = true | ||
show_error_codes = true | ||
plugins = ["pydantic.mypy"] | ||
plugins = ["pydantic.v1.mypy"] | ||
|
||
[tool.pydantic-mypy] | ||
init_forbid_extra = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Compatibiltity Shims for Declarative Typed Argument Parsing. | ||
This package contains compatibility shims for the `pydantic` and `argparse` | ||
modules, so that we can properly maintain version compatibility in one place. | ||
The public interface exposed by this package is the module shims themselves. | ||
""" | ||
|
||
# Local | ||
from pydantic_argparse.compatibility.argparse import argparse as argparse | ||
from pydantic_argparse.compatibility.pydantic import pydantic as pydantic |
2 changes: 1 addition & 1 deletion
2
src/pydantic_argparse/argparse/patches.py → ...dantic_argparse/compatibility/argparse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Compatibility Shim for Pydantic. | ||
In order to support both Pydantic v1 and Pydantic v2, we need to make sure we | ||
import the module correctly: | ||
* For `pydantic~=2.0` there is a working `v1` module. | ||
* For `pydantic==1.10.15` there is a broken `v1` module (with no `fields`). | ||
* For `pydantic<1.10.14` there is no `v1` module. | ||
""" | ||
|
||
|
||
# Pydantic Shim | ||
# There is a bit of fiddling around here to accomodate for the cases outlined | ||
# above, as well as to keep the type-checker and language-server happy. | ||
try: # pragma: no cover | ||
from pydantic import v1 as pydantic | ||
pydantic.fields # noqa: B018 | ||
except (ImportError, AttributeError): # pragma: no cover | ||
import pydantic # type: ignore[no-redef] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.