Skip to content

Commit 73c9520

Browse files
authored
Migrate from mypy to ty (#296)
1 parent ba039b2 commit 73c9520

9 files changed

Lines changed: 479 additions & 373 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ jobs:
1212
- uses: astral-sh/setup-uv@v3
1313
with:
1414
enable-cache: true
15-
# Keep in sync with `Dockerfile`'s `builder`.
16-
version: "0.5.6"
15+
# Keep in sync with pyproject.toml's `tool.uv.required-version`.
16+
version: "0.8.13"
17+
# Keep in sync with pyproject.toml's `project.requires-python`.
1718
- run: uv python install 3.10
1819
- run: uv sync --locked
1920
- run: uv run -m skeleton
2021
- run: uv run ruff format --check
2122
- run: uv run ruff check
22-
- run: uv run mypy
23+
- run: uv run ty check
2324
- run: uv run pytest

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"recommendations": [
3+
"astral-sh.ty",
34
"charliermarsh.ruff",
45
"ms-python.python",
56
"tamasfe.even-better-toml"

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Inspired from https://github.com/astral-sh/uv-docker-example/blob/dee88a8c43be3b16b0ad58f0daee5eaee7e2157a/multistage.Dockerfile.
22

3-
# Keep in sync with `.github/workflows/test.yml`.
4-
FROM ghcr.io/astral-sh/uv:0.5.6-python3.10-bookworm-slim AS builder
3+
# Keep uv version in sync with pyproject.toml's `tool.uv.required-version`.
4+
# Keep Python version in sync with:
5+
# - pyproject.toml's `project.requires-python`.
6+
# - the main stage below.
7+
FROM ghcr.io/astral-sh/uv:0.8.13-python3.10-bookworm-slim AS builder
58

69
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
710

@@ -17,7 +20,7 @@ RUN --mount=type=bind,source=skeleton,target=skeleton_tmp \
1720
mv app/skeleton skeleton && \
1821
rm -r app
1922

20-
# Keep this synced with the builder image.
23+
# Keep this synced with the `builder` stage above.
2124
FROM python:3.10-slim-bookworm
2225

2326
COPY --from=builder /venv app

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ On top of the `atoti` package, it comes with:
77
- Dependency management with [uv](https://docs.astral.sh/uv)
88
- Config management with [Pydantic](https://docs.pydantic.dev/2.6/concepts/pydantic_settings)
99
- Testing with [pytest](https://docs.pytest.org)
10-
- Type checking with [mypy](http://mypy-lang.org)
10+
- Type checking with [ty](https://docs.astral.sh/ty)
1111
- Formatting and linting with [Ruff](https://docs.astral.sh/ruff)
1212
- Continuous testing with [GitHub Actions](https://github.com/features/actions)
1313

app/load_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def read_station_details(
3030
http_client=http_client,
3131
),
3232
)["data"]["stations"]
33-
station_information_df = pd.DataFrame(stations_data)[
33+
station_information_df = pd.DataFrame(stations_data)[ # ty: ignore[no-matching-overload]
3434
["station_id", "name", "capacity", "lat", "lon"]
3535
].rename(
3636
columns={

app/util/reverse_geocode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _reverse_geocode(
8686

8787
results_df = results_df.set_index(list(coordinates_df.columns))
8888
results_df = results_df.rename(columns=_COLUMN_NAME_MAPPING)
89-
return results_df.to_dict("index") # type: ignore[return-value]
89+
return results_df.to_dict("index")
9090

9191

9292
def reverse_geocode(

pyproject.toml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
[dependency-groups]
2-
dev = [
3-
"docker",
4-
"mypy",
5-
"pandas-stubs",
6-
"pytest",
7-
"pytest-asyncio",
8-
"ruff",
9-
]
2+
dev = ["docker", "pandas-stubs", "pytest", "pytest-asyncio", "ruff", "ty"]
103

114
[project]
125
name = "app"
136
version = "0.1.0"
7+
# Keep in sync with:
8+
# - .github/workflows/test.yml
9+
# - Dockerfile`'s `FROM` commands.
1410
requires-python = ">=3.10"
1511
dependencies = [
1612
"atoti[jdbc]",
@@ -22,17 +18,6 @@ dependencies = [
2218
]
2319

2420

25-
[tool.mypy]
26-
files = "app,skeleton,tests" # Remove once https://github.com/python/mypy/issues/10428 is fixed.
27-
strict = true
28-
warn_redundant_casts = true
29-
warn_unused_configs = true
30-
warn_unused_ignores = true
31-
32-
[[tool.mypy.overrides]]
33-
module = ["docker", "docker.*"]
34-
ignore_missing_imports = true
35-
3621
[tool.pytest.ini_options]
3722
addopts = "--doctest-modules --strict-markers"
3823
asyncio_default_fixture_loop_scope = "session"
@@ -71,8 +56,20 @@ select = ["ALL"]
7156
banned-from = ["atoti", "pandas"]
7257

7358
[tool.ruff.lint.flake8-import-conventions.aliases]
74-
atoti = "tt"
59+
atoti = "tt"
7560
pandas = "pd"
7661

7762
[tool.ruff.lint.isort]
7863
combine-as-imports = true
64+
65+
[tool.ty.rules]
66+
unused-ignore-comment = "warn"
67+
68+
[tool.ty.terminal]
69+
error-on-warning = true
70+
71+
[tool.uv]
72+
# Keep in sync with:
73+
# - .github/workflows/test.yml
74+
# - Dockerfile`'s `builder`.
75+
required-version = ">=0.8.13"

tests/docker/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def docker_bin_fixture() -> Path:
2121

2222

2323
@pytest.fixture(name="docker_client", scope="session")
24-
def docker_client_fixture() -> docker.DockerClient:
25-
return docker.from_env()
24+
def docker_client_fixture() -> Generator[docker.DockerClient, None, None]:
25+
client = docker.from_env()
26+
yield client
27+
client.close()
2628

2729

2830
@pytest.fixture(name="docker_image_name", scope="session")
@@ -76,3 +78,4 @@ def session_inside_docker_container_fixture(
7678
)
7779
session = tt.Session.connect(f"http://localhost:{host_port}")
7880
yield session
81+
logs.close()

0 commit comments

Comments
 (0)