Repository navigation
Replace black, isort, flake8, autoflake and pyupgrade with ruff - #761
Draft
zigpy-review-bot wants to merge 4 commits into
Draft
zigpy-review-bot wants to merge 4 commits into
zigpy-review-bot wants to merge 4 commits into
Conversation
Mostly autofixes: import sorting, pyupgrade rewrites, ruff format output (lowercase hex escapes, joined implicit string concatenations) and unused loop variables. By hand: - Remove the stray fourth quote that opened every EZSP version module docstring (`""""EZSP ...`). - Drop a dead `stack_status = asyncio.Future()` in `EZSP.leaveNetwork`, immediately rebound by the `with` statement (F811). - Create the default `RuntimeError` in `_cancel_pending_data_frames` per call instead of sharing one instance created at import time (B008). - Exception chaining for re-raised errors, explicit zip(strict=...), %-formatting -> f-strings in the CLI, and keep a reference to background tasks in a test (RUF006).
Surfaced by the new ruff rules: - test_write_custom_eui64 and test_write_custom_eui64_rcp compared setTokenData.mock_calls without asserting (B015). Asserting them showed the expected calls used positional arguments while the code passes keywords, and the RCP test's getTokenData mock reported success for every key, so the NCP key was picked. The mock now only knows the RCP key. - test_list_command_initial_failure and test_form_network_fail used t.EmberStatus.FAILURE, which no longer exists, so they passed on an AttributeError raised before the code under test ran (B017). They now use ERR_FATAL and check for the specific error.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #761 +/- ##
==========================================
+ Coverage 99.58% 99.60% +0.02%
==========================================
Files 64 64
Lines 4330 4327 -3
==========================================
- Hits 4312 4310 -2
+ Misses 18 17 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Nothing references it (CI runs the shared zigpy/workflows pipeline, not tox), it was last changed in 2020, and its py37/py38 environments cannot run against requires-python >= 3.11.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
#759 bumped only the two hooks that crashed on Python 3.14. The rest of the stack is old (black 23.3.0, isort 5.12.0, autoflake v2.0.2, ruff v0.0.261), and flake8 cannot move at all:
pyproject-flake8==7.0.0pinsflake8==7.0.0exactly, and there is no newer release of it. This replaces the stack with ruff, as zigpy, zha, zha-device-handlers and zigpy-znp already do.Changes
ruff-check+ruff-format(ruff-pre-commit v0.16.9, now underastral-sh/) replaceblack,isort,flake8,autoflake,pyupgradeand the old ruff hook.codespellgoes from v2.2.4 to v2.4.3, andmirrors-mypystays at v2.3.1.ruff.tomlmoves into[tool.ruff]inpyproject.toml, replacing[tool.isort]and[tool.flake8]. The existing rule selection and ignores are kept, with the fullBandSIMfamilies replacing the individualB0xx/SIM1xxcodes andIreplacing isort.tests/was excluded from ruff and only checked by flake8. It is now checked by ruff, with the sameF811, F401, F403per-file ignores flake8 had. flake8'sE266exemption forbellows/types/named.pyis not carried over because ruff only hasE266as a preview rule, which is not enabled.requirements_test.txt: dropisort,black,flake8andFlake8-pyproject, and bumpruff==0.0.261toruff==0.16.9to match the hook.python.json.Second commit, the resulting fixes. Mostly autofixes: import sorting, pyupgrade rewrites, ruff format output (lowercase hex escapes, joined implicit string concatenations) and unused loop variables. By hand:
""""EZSP ...), leaving a stray"in the text.EZSP.leaveNetworkcreated a deadasyncio.Future()that thewithstatement immediately rebinds (F811)._cancel_pending_data_framesdefaulted to a singleRuntimeErrorinstance created at import time and reused on every call (B008). It is now created per call.zip(strict=...),%-formatting → f-strings in the CLI (with!swhere the value is a zigpy enum, whoseformat()returns therepr),# flake8: noqa→# ruff: noqa, and a test that did not keep a reference to its background tasks (RUF006).Third commit: the new rules showed that four tests in
tests/test_ezsp.pycould not fail.test_write_custom_eui64andtest_write_custom_eui64_rcpcomparedsetTokenData.mock_callsagainst the expected calls withoutassert(B015). With theassertadded, both failed. The expectations used positional arguments while the code passes keywords. The RCP test'sgetTokenDatamock also reported success for every key, so the code picked the NCP key, not the RCP one the test is about. The mock now only knows the RCP key, and both tests check the real calls.test_list_command_initial_failureandtest_form_network_failusedt.EmberStatus.FAILURE, which no longer exists. They passed on the resultingAttributeError, raised before the code under test ran (pytest.raises(Exception), B017). They now useERR_FATALand check for the specific error.Fourth commit: remove
tox.ini. Nothing references it (CI runs the shared zigpy/workflows pipeline, not tox), it was last changed in 2020, and itspy37/py38environments cannot run againstrequires-python = ">=3.11".Verification
pre-commit run --all-filespasses on Python 3.14.dev. Coverage stays at 99%, the CI minimum.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.