This commit is contained in:
Eugene Yurtsev
2024-03-15 11:25:51 -04:00
parent 07e3c3594e
commit a6158d8d20
2 changed files with 9 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
from .config import USE_PYDANTIC_V2, _PYDANTIC_VERSION, _PYDANTIC_MAJOR_VERSION
from .config import _PYDANTIC_MAJOR_VERSION, _PYDANTIC_VERSION, USE_PYDANTIC_V2
## Create namespaces for pydantic v1 and v2.
# This code must stay at the top of the file before other modules may
@@ -14,18 +14,19 @@ from .config import USE_PYDANTIC_V2, _PYDANTIC_VERSION, _PYDANTIC_MAJOR_VERSION
try:
if USE_PYDANTIC_V2:
from pydantic import *
from pydantic import * # noqa: F403 # type: ignore
else:
from pydantic.v1 import * # noqa: F403 # type: ignore
except ImportError:
from pydantic import * # noqa: F403 # type: ignore
# Only expose things that are common across all pydantic versions
__all__ = [
"BaseModel",
"Field",
"PrivateAttr",
"SecretStr",
"ValidationError",
"BaseModel", # noqa: F405
"Field", # noqa: F405
"PrivateAttr", # noqa: F405
"SecretStr", # noqa: F405
"ValidationError", # noqa: F405
"USE_PYDANTIC_V2",
"_PYDANTIC_VERSION",
"_PYDANTIC_MAJOR_VERSION",

View File

@@ -1,5 +1,4 @@
import os
from importlib import metadata
_PYDANTIC_VERSION = metadata.version("pydantic")
@@ -14,7 +13,7 @@ def _get_use_pydantic_v2() -> bool:
"""Get the value of the LC_PYDANTIC_V2_UNSAFE environment variable."""
value = os.environ.get("LC_PYDANTIC_V2_UNSAFE", "false").lower()
if value == "true":
if _PYDANTIC_MAJOR_VERSION != 2:
if _PYDANTIC_MAJOR_VERSION != 2:
raise ValueError(
f"LC_PYDANTIC_V2_UNSAFE is set to true, "
f"but pydantic version is {_PYDANTIC_VERSION}"