Skip to content

Commit 81319ad

Browse files
authored
test(core): resolve pydantic_v1 deprecation warning (#33110)
Excluded pydantic_v1 module from import testing Acceptable since this pydantic_v1 is explicitly deprecated. Testing its importability at this stage serves little purpose since users should migrate away from it.
1 parent e3f3c13 commit 81319ad

File tree

2 files changed

+37
-54
lines changed

2 files changed

+37
-54
lines changed

libs/core/tests/unit_tests/test_imports.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,29 @@
11
import concurrent.futures
22
import importlib
33
import subprocess
4-
import warnings
54
from pathlib import Path
65

76

87
def test_importable_all() -> None:
9-
with warnings.catch_warnings():
10-
# Suppress pydantic_v1 deprecation warnings during import testing
11-
# These warnings are expected as modules transition from pydantic v1 to v2
12-
# and are not relevant to testing importability
13-
warnings.filterwarnings(
14-
"ignore",
15-
message=".*langchain_core.pydantic_v1.*",
16-
category=DeprecationWarning,
17-
)
18-
for path in Path("../core/langchain_core/").glob("*"):
19-
module_name = path.stem
20-
if not module_name.startswith(".") and path.suffix != ".typed":
21-
module = importlib.import_module("langchain_core." + module_name)
22-
all_ = getattr(module, "__all__", [])
23-
for cls_ in all_:
24-
getattr(module, cls_)
8+
for path in Path("../core/langchain_core/").glob("*"):
9+
module_name = path.stem
10+
if (
11+
not module_name.startswith(".")
12+
and path.suffix != ".typed"
13+
and module_name != "pydantic_v1"
14+
):
15+
module = importlib.import_module("langchain_core." + module_name)
16+
all_ = getattr(module, "__all__", [])
17+
for cls_ in all_:
18+
getattr(module, cls_)
2519

2620

2721
def try_to_import(module_name: str) -> tuple[int, str]:
2822
"""Try to import a module via subprocess."""
29-
with warnings.catch_warnings():
30-
# Suppress pydantic_v1 deprecation warnings during import testing
31-
# These warnings are expected as modules transition from pydantic v1 to v2
32-
# and are not relevant to testing importability
33-
warnings.filterwarnings(
34-
"ignore",
35-
message=".*langchain_core.pydantic_v1.*",
36-
category=DeprecationWarning,
37-
)
38-
module = importlib.import_module("langchain_core." + module_name)
39-
all_ = getattr(module, "__all__", [])
40-
for cls_ in all_:
41-
getattr(module, cls_)
23+
module = importlib.import_module("langchain_core." + module_name)
24+
all_ = getattr(module, "__all__", [])
25+
for cls_ in all_:
26+
getattr(module, cls_)
4227

4328
result = subprocess.run(
4429
["python", "-c", f"import langchain_core.{module_name}"], check=True
@@ -56,7 +41,11 @@ def test_importable_all_via_subprocess() -> None:
5641
module_names = []
5742
for path in Path("../core/langchain_core/").glob("*"):
5843
module_name = path.stem
59-
if not module_name.startswith(".") and path.suffix != ".typed":
44+
if (
45+
not module_name.startswith(".")
46+
and path.suffix != ".typed"
47+
and module_name != "pydantic_v1"
48+
):
6049
module_names.append(module_name)
6150

6251
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
import importlib
2-
import warnings
32
from pathlib import Path
43

54
from pydantic import BaseModel
65

76

87
def test_all_models_built() -> None:
9-
with warnings.catch_warnings():
10-
# Suppress pydantic_v1 deprecation warnings during import testing
11-
# These warnings are expected as modules transition from pydantic v1 to v2
12-
# and are not relevant to testing pydantic model completeness
13-
warnings.filterwarnings(
14-
"ignore",
15-
message=".*langchain_core.pydantic_v1.*",
16-
category=DeprecationWarning,
17-
)
18-
for path in Path("../core/langchain_core/").glob("*"):
19-
module_name = path.stem
20-
if not module_name.startswith(".") and path.suffix != ".typed":
21-
module = importlib.import_module("langchain_core." + module_name)
22-
all_ = getattr(module, "__all__", [])
23-
for attr_name in all_:
24-
attr = getattr(module, attr_name)
25-
try:
26-
if issubclass(attr, BaseModel):
27-
assert attr.__pydantic_complete__ is True
28-
except TypeError:
29-
# This is expected for non-class attributes
30-
pass
8+
for path in Path("../core/langchain_core/").glob("*"):
9+
module_name = path.stem
10+
if (
11+
not module_name.startswith(".")
12+
and path.suffix != ".typed"
13+
and module_name != "pydantic_v1"
14+
):
15+
module = importlib.import_module("langchain_core." + module_name)
16+
all_ = getattr(module, "__all__", [])
17+
for attr_name in all_:
18+
attr = getattr(module, attr_name)
19+
try:
20+
if issubclass(attr, BaseModel):
21+
assert attr.__pydantic_complete__ is True
22+
except TypeError:
23+
# This is expected for non-class attributes
24+
pass

0 commit comments

Comments
 (0)