Skip to content

Fix ruff target version and mypy pre-commit hook - #9

Merged
puddly merged 2 commits into
zigpy:devfrom
zigpy-review-bot:zigpy-bot/fix-ruff-target-and-mypy-hook
Sep 29, 2026
Merged

puddly merged 2 commits into
zigpy:devfrom
zigpy-review-bot:zigpy-bot/fix-ruff-target-and-mypy-hook

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Contributor

Problems

  • [tool.ruff] target-version = "py39" does not match requires-python = ">=3.12". ruff 0.6.2 accepted the existing match statement anyway, but current ruff reports it as invalid-syntax for Python 3.9.
  • The local mypy hook runs uv run --frozen mypy, but mypy is in the testing dependency group. In a venv synced without that group (for example after a plain uv sync), the hook fails with "Failed to spawn: mypy". CI is unaffected because it syncs the ci group, which includes testing.

Changes

  • target-version = "py312", matching requires-python.
  • The mypy hook runs uv run --frozen --group testing mypy.
  • ruff-pre-commit v0.6.2 → v0.16.9 (hook id ruff → ruff-check, the old id is now a legacy alias) and codespell v2.3.0 → v2.4.3.
  • Second commit: the resulting ruff changes, timezone.utc → UTC (UP017, from the new target) and ruff 0.16's parenthesized multi-line lambda bodies. No behaviour change.

Verification

  • pre-commit run --all-files passes on Python 3.14, including mypy in a venv without the testing group.
  • Tests: 101 passed.

Context

This is one of a set of draft PRs that align the pre-commit setup of the zigpy libraries on ruff (ruff check + ruff format), which zigpy, zha, zha-device-handlers, zigpy-znp, zigpy-ota and zigpy-ziggurat already use. The same change is proposed for bellows, zigpy-deconz, zigpy-xbee, zigpy-zigate and zigpy-cli, plus small ruff config fixes in zigpy and zigpy-ziggurat.

The commits are kept separate so parts can be dropped or moved into their own PR. Maintainers can ask the bot for that, or for any other change, by commenting @zigpy-review-bot <request> on this PR.

- ruff target-version py39 -> py312, matching requires-python = ">=3.12". Newer ruff rejects the existing `match` statement as invalid syntax under py39.
- Run the local mypy hook with `--group testing`: mypy lives in that dependency group, so `uv run --frozen mypy` failed to spawn in a venv synced without it.
- Bump ruff-pre-commit v0.6.2 -> v0.16.9 (hook id `ruff` -> `ruff-check`) and codespell v2.3.0 -> v2.4.3.
UP017 (`timezone.utc` -> `UTC`) from the py312 target, and ruff 0.16's parenthesized multi-line lambda bodies. No behaviour change.
@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2e209a1) to head (90bd027).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev        #9   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines         1185      1185           
=========================================
  Hits          1185      1185           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES
TheJulianJES marked this pull request as ready for review September 28, 2026 01:47
Copilot AI lite review requested due to automatic review settings September 28, 2026 01:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain, and all verification checks pass.

Review effort: Lite
Findings: None

What changed in this PR

Updates Ruff and pre-commit configuration for Python 3.12, fixes mypy dependency resolution, and applies resulting formatting changes.

Changes:

  • Targets Ruff at Python 3.12.
  • Updates Ruff and codespell hooks.
  • Runs mypy with the testing dependency group.
  • Modernizes UTC usage and formats multiline lambdas.
File Description
zigpy_ziggurat/​zigbee/​wire.py Ruff formatting updates
zigpy_ziggurat/​zigbee/​application.py Uses datetime.UTC
pyproject.toml Sets Ruff target to Python 3.12
.pre-commit-config.yaml Updates hooks and mypy invocation

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@puddly
puddly merged commit 7a6bc8b into zigpy:dev Sep 29, 2026
10 checks passed
@zigpy-review-bot zigpy-review-bot added the code quality Improvement to code quality label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvement to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants