Skip to content

Commit 0bd97cf

Browse files
committed
Replace mypy with zuban: add pre-commit hook, convert [tool.mypy] to [tool.zuban] with default mode, and fix test type narrowing
1 parent 6c6e74c commit 0bd97cf

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
repos:
2+
- repo: local
3+
hooks:
4+
- id: zuban
5+
name: zuban
6+
entry: uv run zuban check homeassistant_api
7+
language: system
8+
types: [python]
9+
pass_filenames: false
210
- repo: https://github.com/pre-commit/pre-commit-hooks
311
hooks:
412
- id: trailing-whitespace

pyproject.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ docs = [
3030
"autodoc-pydantic>=2,<3",
3131
]
3232
dev = [
33-
"pre-commit>=4,<5",
3433
"types-docutils>=0.22",
3534
"types-simplejson>=3.20",
3635
"types-toml>=0.10",
@@ -40,6 +39,7 @@ dev = [
4039
"pytest-cov>=7",
4140
"pytest>=8",
4241
"aiosqlite>=0.22",
42+
"prek>=0.3.8",
4343
]
4444

4545
[tool.pytest.ini_options]
@@ -99,14 +99,9 @@ ignore = [
9999
[tool.ruff.lint.isort]
100100
force-single-line = true
101101

102-
[tool.mypy]
103-
disable_error_code = [
104-
"no-untyped-def",
105-
"name-defined",
106-
]
107-
exclude = [
108-
"^docs/"
109-
]
102+
[tool.zuban]
103+
exclude = ["^docs/"]
104+
untyped_function_return_mode = "inferred"
110105

111106
[tool.hatch.build.targets.wheel]
112107
packages = ["homeassistant_api"]

tests/test_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ def test_prepare_entity_histories_naive_timestamps() -> None:
7272
end_timestamp=naive_end,
7373
)
7474
# Naive timestamps should get a timezone attached
75-
assert "+" in url or "-" in url.split("T")[-1], (
76-
"start_timestamp should have timezone offset"
77-
)
78-
assert "+" in params["end_time"] or "-" in params["end_time"].split("T")[-1], (
79-
"end_time should have timezone offset"
80-
)
75+
start_time = datetime.fromisoformat(url.split("/")[-1])
76+
assert start_time.tzinfo is not None, "start_timestamp should have timezone offset"
77+
end_time_str = params["end_time"]
78+
assert end_time_str is not None
79+
end_time = datetime.fromisoformat(end_time_str)
80+
assert end_time.tzinfo is not None, "end_time should have timezone offset"
8181

8282

8383
# --- BaseClient: prepare_get_logbook_entry_params ---

0 commit comments

Comments
 (0)