Skip to content

Commit 786543e

Browse files
committed
feat: add ty type checker as prek hook
Add ty (Astral's Rust-based type checker) alongside existing linting: - Add ty as dev dependency with error-on-warning config - Add local-ty prek hook (language: unsupported, serial, full check) - Fix type errors found by ty (api.py return type, unused type: ignore)
1 parent 36e0b56 commit 786543e

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ repos:
4949
rev: 0.10.12
5050
hooks:
5151
- id: uv-lock
52+
- repo: local
53+
hooks:
54+
- id: local-ty
55+
name: ty check
56+
entry: uv run ty check template tests
57+
require_serial: true
58+
language: unsupported
59+
pass_filenames: false

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ xfail_strict = true
7474
addopts = ["-ra", "--strict-config", "--strict-markers"]
7575
filterwarnings = ["error", "ignore::DeprecationWarning"]
7676

77+
[tool.ty.terminal]
78+
error-on-warning = true
79+
7780
[dependency-groups]
7881
dev = [
7982
"pytest",
8083
"ruff",
8184
"prek",
8285
"ipykernel",
86+
"ty",
8387
]

template/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def read_root() -> dict[str, str]:
4343
@app.post("/predict")
4444
def predict(request: Request) -> Response:
4545
"""Mock prediction endpoint."""
46-
return {"output": request.input}
46+
return Response(output=request.input)
4747

4848

4949
if __name__ == "__main__":

template/main.py

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

55
from importlib.metadata import PackageNotFoundError, version
66

7-
import typer # type: ignore
7+
import typer
88

99
try:
1010
__version__: str | None = version("template")

uv.lock

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)