Skip to content

Commit 318a6c2

Browse files
committed
chore: Use ty for type checking
1 parent fc2d5fe commit 318a6c2

5 files changed

Lines changed: 87 additions & 2 deletions

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := /bin/bash
22

3-
.PHONY: help develop install-dev install-deps fixup test test-core test-wheel lint pylint nox
3+
.PHONY: help develop install-dev install-deps fixup test test-core test-wheel lint pylint typecheck nox
44

55
develop: install-dev
66
mise exec -- pre-commit install
@@ -30,6 +30,9 @@ lint:
3030
pylint:
3131
mise exec -- $(MAKE) -C py pylint
3232

33+
typecheck:
34+
mise exec -- $(MAKE) -C py typecheck
35+
3336
nox: test
3437

3538
help:
@@ -40,6 +43,7 @@ help:
4043
@echo " install-dev - Install pinned tools and create/update the repo env via mise"
4144
@echo " lint - Run pre-commit hooks plus Python SDK pylint via py/Makefile"
4245
@echo " pylint - Run Python SDK pylint only via py/Makefile"
46+
@echo " typecheck - Run ty type checker on the Python SDK via py/Makefile"
4347
@echo " nox - Alias for test"
4448
@echo " test - Run the Python SDK nox matrix via py/Makefile"
4549
@echo " test-core - Run Python SDK core tests via py/Makefile"

mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _.file = ".env"
1212

1313
[tools]
1414
ruff = "0.12.7"
15+
ty = "0.0.23"
1516

1617
[hooks]
1718
postinstall = "make install-deps"

py/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PYTHON ?= python
22
UV := $(PYTHON) -m uv
33
UV_VERSION := $(shell awk '$$1=="uv" { print $$2 }' ../.tool-versions)
44

5-
.PHONY: lint pylint test test-wheel _template-version clean fixup build verify-build verify help install-build-deps install-dev install-optional test-core _check-git-clean
5+
.PHONY: lint pylint typecheck test test-wheel _template-version clean fixup build verify-build verify help install-build-deps install-dev install-optional test-core _check-git-clean
66

77
clean:
88
rm -rf build dist
@@ -17,6 +17,9 @@ lint: fixup
1717
pylint:
1818
nox -s pylint
1919

20+
typecheck:
21+
ty check
22+
2023
test:
2124
nox -x
2225

@@ -73,6 +76,7 @@ help:
7376
@echo " install-dev - Install package in development mode with all dependencies"
7477
@echo " lint - Run pylint checks"
7578
@echo " pylint - Run pylint without pre-commit hooks"
79+
@echo " typecheck - Run ty type checker"
7680
@echo " test - Run all tests"
7781
@echo " test-core - Run core tests only"
7882
@echo " test-wheel - Run tests against built wheel"

py/noxfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ def pylint(session):
315315
session.run("pylint", "--errors-only", *files)
316316

317317

318+
@nox.session(venv_backend="none")
319+
def typecheck(session):
320+
"""Run the ty type checker.
321+
322+
ty is installed via mise (see mise.toml) and reads its configuration from
323+
py/ty.toml. It does not need optional vendor packages because
324+
allowed-unresolved-imports suppresses those diagnostics.
325+
"""
326+
session.run("ty", "check", *session.posargs, external=True)
327+
328+
318329
@nox.session()
319330
def test_latest_wrappers_novcr(session):
320331
"""Run the latest wrapper tests without vcrpy."""

py/ty.toml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[environment]
2+
python-version = "3.10"
3+
# Use the repo-level venv for third-party stubs/packages.
4+
python = "../venv"
5+
6+
[src]
7+
# Focus on the SDK source tree; integration packages and examples have their
8+
# own (often uninstalled) dependency surfaces and are better checked separately.
9+
include = ["src/"]
10+
exclude = [
11+
"**/__pycache__/",
12+
]
13+
14+
[rules]
15+
# Start with errors-only to match the existing pylint --errors-only baseline.
16+
# Warnings can be promoted to errors later as the codebase is cleaned up.
17+
18+
[analysis]
19+
# Optional provider packages are imported behind try/except guards.
20+
# Suppress unresolved-import for all of them so ty can run without
21+
# installing the full dependency surface (matching how test_core works).
22+
# Use ** to match arbitrarily deep submodules (e.g. opentelemetry.sdk.trace).
23+
allowed-unresolved-imports = [
24+
"agno.**",
25+
"agents.**",
26+
"anthropic.**",
27+
"autoevals.**",
28+
"boto3.**",
29+
"botocore.**",
30+
"braintrust_core.**",
31+
"claude_agent_sdk.**",
32+
"dspy.**",
33+
"google.adk.**",
34+
"google.genai.**",
35+
"httpx.**",
36+
"langchain.**",
37+
"langchain_anthropic.**",
38+
"langchain_core.**",
39+
"langchain_openai.**",
40+
"langsmith.**",
41+
"litellm.**",
42+
"logfire.**",
43+
"mcp.**",
44+
"openai.**",
45+
"opentelemetry.**",
46+
"orjson.**",
47+
"pydantic_ai.**",
48+
"starlette.**",
49+
"temporalio.**",
50+
"tenacity.**",
51+
"uvicorn.**",
52+
"aiohttp.**",
53+
"anyio.**",
54+
]
55+
56+
[terminal]
57+
output-format = "full"
58+
59+
# Relax rules for test files – they use mocks, dynamic fixtures, etc.
60+
[[overrides]]
61+
include = ["src/**/test_*.py", "src/**/conftest.py"]
62+
[overrides.rules]
63+
invalid-argument-type = "warn"
64+
unresolved-attribute = "warn"
65+
call-non-callable = "warn"

0 commit comments

Comments
 (0)