From 3819081117354602eb5a6db9a27f261c80224a59 Mon Sep 17 00:00:00 2001 From: Adam Logan Date: Wed, 2 Dec 2026 21:18:33 -0800 Subject: [PATCH] Switch type checker from zuban to ty Replace zuban with ty 1.0 in dev deps, pre-commit, and CI. Fix the two incompatible-mutable-override errors ty reports: BaseEntity now exposes `group` as a type-checking-only read-only property, so Entity and AsyncEntity can narrow the concrete field type soundly. --- .github/workflows/test-suite.yml | 4 ++-- .pre-commit-config.yaml | 6 +++--- docs/CONTRIBUTING.rst | 2 +- homeassistant_api/models/entity.py | 7 ++++++- pyproject.toml | 6 +----- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 54048476..74bf5b9a 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -33,8 +33,8 @@ jobs: run: uv run ruff format homeassistant_api - name: Run Ruff linting run: uv run ruff check homeassistant_api - - name: Run Zuban - run: uv run zuban check homeassistant_api + - name: Run ty + run: uv run ty check homeassistant_api code_functionality: name: "Code Functionality" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0eea4abd..3eb18ee6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,9 @@ repos: - repo: local hooks: - - id: zuban - name: zuban - entry: uv run zuban check homeassistant_api + - id: ty + name: ty + entry: uv run ty check homeassistant_api language: system types: [python] pass_filenames: false diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst index 5f63961f..c27f5bbf 100644 --- a/docs/CONTRIBUTING.rst +++ b/docs/CONTRIBUTING.rst @@ -136,7 +136,7 @@ Code Styling Guidelines In order to make sure that our code is easy to read, and navigate as well as to stop stupid mistakes like typos, undefined variables, etc, we enforce code standards. -Using the tools, :code:`ruff`, :code:`zuban`, and :code:`pytest`, we make sure that our code quality is top notch and that changes work everywhere. +Using the tools, :code:`ruff`, :code:`ty`, and :code:`pytest`, we make sure that our code quality is top notch and that changes work everywhere. You can run those tools manually yourself, but they also run automatically when you open a Pull Request on :resource:`GitHub `. diff --git a/homeassistant_api/models/entity.py b/homeassistant_api/models/entity.py index 3efbaa8d..c8ac167a 100644 --- a/homeassistant_api/models/entity.py +++ b/homeassistant_api/models/entity.py @@ -96,7 +96,12 @@ class BaseEntity(BaseModel): slug: str state: State - group: "BaseGroup" = Field(exclude=True, repr=False) + + if TYPE_CHECKING: + # Subclasses declare the concrete ``group`` field. It is read-only here + # so they can narrow its type without an unsound mutable override. + @property + def group(self) -> BaseGroup: ... @property def entity_id(self) -> str: diff --git a/pyproject.toml b/pyproject.toml index 6ba90289..fbd57147 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ dev = [ "types-docutils>=0.22", "types-simplejson>=3.20", "types-toml>=0.10", - "zuban>=0.7", "ruff>=0.15", "pytest-asyncio>=1", "pytest-cov>=7", @@ -44,6 +43,7 @@ dev = [ "prek>=0.3.8", "pre-commit>=4.5.1", "nimax", + "ty>=1", ] [tool.nimax] @@ -110,10 +110,6 @@ ignore = [ [tool.ruff.lint.isort] force-single-line = true -[tool.zuban] -exclude = ["^docs/"] -untyped_function_return_mode = "inferred" - [tool.hatch.build.targets.wheel] packages = ["homeassistant_api"]