Skip to content

Commit e3c4aea

Browse files
cbornetmdrxy
andauthored
chore(cli): add mypy strict checking (#32386)
Co-authored-by: Mason Daugherty <mason@langchain.dev>
1 parent 4449399 commit e3c4aea

File tree

9 files changed

+70
-48
lines changed

9 files changed

+70
-48
lines changed

libs/cli/langchain_cli/namespaces/migrate/generate/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ImportExtractor(ast.NodeVisitor):
2424

2525
def __init__(self, *, from_package: Optional[str] = None) -> None:
2626
"""Extract all imports from the given code, optionally filtering by package."""
27-
self.imports: list = []
27+
self.imports: list[tuple[str, str]] = []
2828
self.package = from_package
2929

3030
@override

libs/cli/langchain_cli/namespaces/migrate/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import rich
66
import typer
7-
from gritql import run # type: ignore[import]
7+
from gritql import run # type: ignore[import-untyped]
88
from typer import Option
99

1010

@@ -68,7 +68,7 @@ def migrate(
6868
final_code = run.apply_pattern(
6969
"langchain_all_migrations()",
7070
args,
71-
grit_dir=get_gritdir_path(),
71+
grit_dir=str(get_gritdir_path()),
7272
)
7373

7474
raise typer.Exit(code=final_code)

libs/cli/langchain_cli/project_template/app/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@app.get("/")
9-
async def redirect_root_to_docs():
9+
async def redirect_root_to_docs() -> RedirectResponse:
1010
return RedirectResponse("/docs")
1111

1212

libs/cli/langchain_cli/utils/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def create_events(events: list[EventDict]) -> Optional[dict[str, Any]]:
4848

4949
res = conn.getresponse()
5050

51-
return json.loads(res.read())
51+
response_data = json.loads(res.read())
52+
return response_data if isinstance(response_data, dict) else None
5253
except (http.client.HTTPException, OSError, json.JSONDecodeError) as exc:
5354
typer.echo(f"Error sending events: {exc}")
5455
return None

libs/cli/langchain_cli/utils/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import shutil
77
from collections.abc import Sequence
88
from pathlib import Path
9-
from typing import Optional, TypedDict
9+
from typing import Any, Optional, TypedDict
1010

1111
from git import Repo
1212

@@ -26,7 +26,7 @@ class DependencySource(TypedDict):
2626
ref: Optional[str]
2727
subdirectory: Optional[str]
2828
api_path: Optional[str]
29-
event_metadata: dict
29+
event_metadata: dict[str, Any]
3030

3131

3232
# use poetry dependency string format

libs/cli/pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ langchain = "langchain_cli.cli:app"
2929
langchain-cli = "langchain_cli.cli:app"
3030

3131
[dependency-groups]
32-
dev = ["pytest<8.0.0,>=7.4.2", "pytest-watcher<1.0.0,>=0.3.4"]
33-
lint = ["ruff<0.13,>=0.12.2", "mypy<2.0.0,>=1.13.0"]
32+
dev = ["pytest<9.0.0,>=7.4.2", "pytest-watcher<1.0.0,>=0.3.4"]
33+
lint = ["ruff<0.13,>=0.12.2", "mypy<1.18,>=1.17.1"]
3434
test = ["langchain-core", "langchain"]
3535
typing = ["langchain"]
3636
test_integration = []
@@ -82,6 +82,11 @@ pyupgrade.keep-runtime-typing = true
8282
"scripts/**" = [ "INP", "S",]
8383

8484
[tool.mypy]
85+
plugins = ["pydantic.mypy"]
86+
strict = true
87+
enable_error_code = "deprecated"
88+
warn_unreachable = true
89+
8590
exclude = [
8691
"langchain_cli/integration_template",
8792
"langchain_cli/package_template",

libs/cli/scripts/generate_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def cli() -> None:
5252
def generic(
5353
pkg1: str,
5454
pkg2: str,
55-
output: str,
55+
output: Optional[str],
5656
filter_by_all: bool, # noqa: FBT001
5757
format_: str,
5858
) -> None:

libs/cli/tests/unit_tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Any, Optional
22

33
import pytest
44

@@ -16,7 +16,7 @@ def _assert_dependency_equals(
1616
git: Optional[str] = None,
1717
ref: Optional[str] = None,
1818
subdirectory: Optional[str] = None,
19-
event_metadata: Optional[dict] = None,
19+
event_metadata: Optional[dict[str, Any]] = None,
2020
) -> None:
2121
if dep["git"] != git:
2222
msg = f"Expected git to be {git} but got {dep['git']}"

libs/cli/uv.lock

Lines changed: 52 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)