-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pydantic compatibility submodule
- Loading branch information
Showing
2 changed files
with
53 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""A compatibility layer for pydantic 1 and 2.""" | ||
|
||
from pydantic import __version__ as pydantic_version | ||
|
||
__all__ = [ | ||
"PYDANTIC_V1", | ||
"field_validator", | ||
"get_field_validator_values", | ||
] | ||
|
||
PYDANTIC_V1 = pydantic_version.startswith("1.") | ||
|
||
if PYDANTIC_V1: | ||
from pydantic import validator as field_validator | ||
else: | ||
from pydantic import field_validator | ||
|
||
|
||
def get_field_validator_values(values, key: str): | ||
"""Get the value for the key from a field validator object, cross-compatible with Pydantic 1 and 2.""" | ||
if PYDANTIC_V1: | ||
return values[key] | ||
else: | ||
return values.data[key] # type:ignore |
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