Skip to content

Replace black, isort, flake8 and pyupgrade with ruff - #181

Draft
zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/migrate-to-ruff
Draft

zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/migrate-to-ruff

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator

Changes

The pinned hooks still pass, but they are old: black 23.9.1, isort 5.12.0, ruff v0.0.291, pyupgrade v3.15.0, mypy v1.6.0. The flake8 plugin pins (for example pycodestyle==2.11.0) also conflict with current flake8, so it cannot be bumped without re-pinning every plugin. This replaces the stack with ruff.

  • Hooks: ruff-check + ruff-format (ruff-pre-commit v0.16.9) replace black, isort, flake8 (with its plugins), autoflake, pyupgrade and the old ruff hook. codespell goes from v2.2.6 to v2.4.3 and mirrors-mypy from v1.6.0 to v2.3.1.
  • [tool.isort] and [tool.flake8] become [tool.ruff]. The rules are B, C, E, F, I, SIM, UP, W, the set zigpy-znp uses, plus the families of the flake8 plugins that were installed: D (pep257 convention, D202 ignored as before), YTT and ASYNC. E501 stays enforced, as it was under flake8.
  • requirements_test.txt: drop isort, black, flake8 and Flake8-pyproject, and pin ruff==0.16.9 to match the hook.
  • Remove the unused flake8 problem matcher. The shared CI workflow only loads python.json.
  • Second commit: the resulting fixes. Mostly autofixes: dict.fromkeys (C420), a redundant dict.get default (SIM910), contextlib.suppress (SIM105), simplified boolean returns in tests (SIM103), and lowercase hex escapes from ruff format. By hand: exception chaining for re-raised errors, explicit zip(strict=...) (strict=False where the lengths may differ, keeping the current behaviour), a merged nested with statement, and a test that evaluated a property without asserting on it.

Verification

  • pre-commit run --all-files passes on Python 3.14.
  • Tests: 107 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.

Autofixes: C420 (dict.fromkeys), SIM910 (dict.get default), SIM103, SIM105 (contextlib.suppress) and lowercase hex escapes from ruff format. By hand: exception chaining for re-raised errors, explicit zip(strict=...) (strict=False where the lengths may differ, keeping the current behaviour), a merged nested `with` statement, and a test that evaluated a property without asserting on it.
@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 (1b81d91) to head (56353b0).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          733       730    -3     
=========================================
- Hits           733       730    -3     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant