Use zigpy's mypy exclude generation tool for stricter types#773
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #773 +/- ##
=======================================
Coverage 97.41% 97.41%
=======================================
Files 50 50
Lines 10419 10419
=======================================
Hits 10150 10150
Misses 269 269 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| uv pip install -r requirements_test.txt | ||
| uv pip install -e . | ||
| uv pip install -U pip setuptools | ||
| uv pip install -e . --group testing |
There was a problem hiding this comment.
We may even just want to use uv sync here, similar to what’s done in the quirks repo. I think the GH CI from our shared workflow will already do this now, so might be good to keep the setup script in sync?
zigpy-review-bot
left a comment
There was a problem hiding this comment.
Verified end-to-end.
python -m mypy zha/in a fresh worktree against mypy 2.1.0 returnsSuccess: no issues found in 52 source files, vs 78 errors in 18 files on dev (fd3fbb9b). The per-module overrides codify existing debt with finer granularity than the previous global suppression list, which also lets new error categories (assignment,override,union-attr,attr-defined) trip mypy in modules where they aren't suppressed — meaningful net stricter.python -m tools.regenerate_mypy_ignoresis idempotent against the committedpyproject.toml— re-running on the worktree produces no diff.- The
endpoint.pyimport fix is load-bearing:from zigpy import Endpointactually raisesImportError(zigpy/__init__.pydoesn't re-export it), so the previous form only resolved because it wasTYPE_CHECKING-guarded. The newfrom zigpy.endpoint import Endpoint as ZigpyEndpointis the right shape for mypy to actually resolveZigpyEndpointto a class. - New direct enum imports (
PanelStatus,ArmMode,ArmNotification,AlarmStatus,WindowCoveringType,ColorCapabilities,Options) all resolve to the same objects as the class-nested forms — pure annotation cleanup, no call-site behavior change. - Pre-commit log confirms
mypy ... Passedruns as a real check now (previously the isolated env had nozigpy/zhaquirksand every import collapsed toAnyunderignore_missing_imports).
Optional / consider — cross-repo parity with zigpy/zha-device-handlers
The quirks repo already runs the lock-file pattern this PR introduces here, and has settled on a slightly more consistent shape:
-
uv syncinscript/setuprather thanuv pip install -e . --group testing. The PR commitsuv.lockand usesuv run --frozenin pre-commit, butscript/setupusesuv pip install, which doesn't consult the lock. So pre-commit runs against pinned versions while the rest of the venv is resolved fresh each setup.uv syncwould honor the lock everywhere and pick up the new[tool.uv] default-groups = ["testing"]declaration in one command. Quirksscript/setupalready does this. -
Add a
uv-lock --checkpre-commit hook. Quirks has:- repo: https://github.com/astral-sh/uv-pre-commit rev: 0.8.6 hooks: - id: uv-lock args: ["--check"]
Without it, a contributor bumping a dep in
[dependency-groups]without re-locking won't get caught untiluv run --frozenfails on someone else's machine. -
.venvvsvenv/. Minor: uv defaults to.venvand the quirks repo + the existing developer venv both follow that. The PR keeps the pre-existing explicitvenv/name; both are gitignored so it's harmless, but renaming to.venvwould match the new uv-centric tooling and the sister repo.
This PR copies the zigpy
python -m tools.regenerate_mypy_ignorestool for granular typing excludes. I've migrated us topyproject.tomlwithciandtestingsections.As a test, I've fixed a few small
unreachableandinvalid-typeissues in this PR as well.