update pydantic namespace

This commit is contained in:
Eugene Yurtsev
2024-09-13 12:58:09 -04:00
parent 1bf9a04f26
commit f16da0c9d3
7 changed files with 21 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
def _raise_import_error() -> None: def _raise_import_error() -> None:
"""Raise ImportError with a helpful message.""" """Raise ImportError with a helpful message."""
raise ImportError( raise ImportError(
"Please do not import from langchain_core.pydantic_v1.*." "Please do not import from langchain_core.pydantic_v1. "
"This module was a compatibility shim for pydantic v1, and should " "This module was a compatibility shim for pydantic v1, and should "
"no longer be used " "no longer be used "
"Please update the code to import from Pydantic directly. " "Please update the code to import from Pydantic directly. "

View File

@@ -1,7 +1,7 @@
def _raise_import_error() -> None: def _raise_import_error() -> None:
"""Raise ImportError with a helpful message.""" """Raise ImportError with a helpful message."""
raise ImportError( raise ImportError(
"Please do not import from langchain_core.pydantic_v1.*." "Please do not import from langchain_core.pydantic_v1. "
"This module was a compatibility shim for pydantic v1, and should " "This module was a compatibility shim for pydantic v1, and should "
"no longer be used " "no longer be used "
"Please update the code to import from Pydantic directly. " "Please update the code to import from Pydantic directly. "

View File

@@ -1,7 +1,7 @@
def _raise_import_error() -> None: def _raise_import_error() -> None:
"""Raise ImportError with a helpful message.""" """Raise ImportError with a helpful message."""
raise ImportError( raise ImportError(
"Please do not import from langchain_core.pydantic_v1.*." "Please do not import from langchain_core.pydantic_v1. "
"This module was a compatibility shim for pydantic v1, and should " "This module was a compatibility shim for pydantic v1, and should "
"no longer be used " "no longer be used "
"Please update the code to import from Pydantic directly. " "Please update the code to import from Pydantic directly. "

View File

@@ -12,6 +12,8 @@ def test_importable_all() -> None:
if relative_path.endswith(".typed"): if relative_path.endswith(".typed"):
continue continue
module_name = relative_path.split(".")[0] module_name = relative_path.split(".")[0]
if module_name.startswith("pydantic_v1"):
continue
module = importlib.import_module("langchain_core." + module_name) module = importlib.import_module("langchain_core." + module_name)
all_ = getattr(module, "__all__", []) all_ = getattr(module, "__all__", [])
for cls_ in all_: for cls_ in all_:
@@ -42,6 +44,10 @@ def test_importable_all_via_subprocess() -> None:
relative_path = Path(path).parts[-1] relative_path = Path(path).parts[-1]
if relative_path.endswith(".typed"): if relative_path.endswith(".typed"):
continue continue
# pydantic_v1 has been deprecated and intentionally
# raises an ImportError when imported.
if relative_path.startswith("pydantic_v1"):
continue
module_name = relative_path.split(".")[0] module_name = relative_path.split(".")[0]
module_names.append(module_name) module_names.append(module_name)

View File

@@ -1,7 +1,7 @@
def _raise_import_error() -> None: def _raise_import_error() -> None:
"""Raise ImportError with a helpful message.""" """Raise ImportError with a helpful message."""
raise ImportError( raise ImportError(
"Please do not import from langchain.pydantic_v1.*." "Please do not import from langchain.pydantic_v1. "
"This module was a compatibility shim for pydantic v1, and should " "This module was a compatibility shim for pydantic v1, and should "
"no longer be used " "no longer be used "
"Please update the code to import from Pydantic directly. " "Please update the code to import from Pydantic directly. "

View File

@@ -1,7 +1,7 @@
def _raise_import_error() -> None: def _raise_import_error() -> None:
"""Raise ImportError with a helpful message.""" """Raise ImportError with a helpful message."""
raise ImportError( raise ImportError(
"Please do not import from langchain.pydantic_v1.*." "Please do not import from langchain.pydantic_v1. "
"This module was a compatibility shim for pydantic v1, and should " "This module was a compatibility shim for pydantic v1, and should "
"no longer be used " "no longer be used "
"Please update the code to import from Pydantic directly. " "Please update the code to import from Pydantic directly. "

View File

@@ -24,6 +24,11 @@ def test_import_all() -> None:
# Without init # Without init
module_name = module_name.rsplit(".", 1)[0] module_name = module_name.rsplit(".", 1)[0]
# pydantic_v1 name space is deprecated and will intentionally raise an
# ImportError
if module_name.startswith("langchain.pydantic_v1"):
continue
mod = importlib.import_module(module_name) mod = importlib.import_module(module_name)
all = getattr(mod, "__all__", []) all = getattr(mod, "__all__", [])
@@ -61,6 +66,11 @@ def test_import_all_using_dir() -> None:
if module_name.startswith("langchain_community.") and COMMUNITY_NOT_INSTALLED: if module_name.startswith("langchain_community.") and COMMUNITY_NOT_INSTALLED:
continue continue
# pydantic_v1 name space is deprecated and will intentionally raise an
# ImportError
if module_name.startswith("langchain.pydantic_v1"):
continue
try: try:
mod = importlib.import_module(module_name) mod = importlib.import_module(module_name)
except ModuleNotFoundError as e: except ModuleNotFoundError as e: