style: apply Ruff's remaining automatic fixes - #283
Merged
Conversation
Picks up the 110 findings #282 left behind because they need `--unsafe-fixes`. Ruff calls them unsafe where a fix can alter meaning rather than only layout, so every one of them was read rather than trusted. 230 findings -> 121 75 file/rule pairs in the baseline -> 36 23 files with findings -> 17 Two thirds are D415, a full stop at the end of a docstring's first line. Fifteen of those docstrings belong to click commands, which use them as help text, so `audible --help` now reads "Interact with library." where it read "Interact with library" before. `activation-bytes` already ended in a full stop, so this makes the list consistent rather than changing its style. W291 and W293 strip trailing whitespace. Ruff treats that as unsafe because whitespace inside a string is content, and 24 of these lines are exactly that, spread over the quickstart intro, two click help texts and several docstrings. None of it shows: the intro goes to `secho()` unchanged and a space before a line break is invisible in a terminal, while click rewraps help text anyway. `audible api --help` differs only by the added full stop. Two changes are neither cosmetic nor a rewrite. `_logging.py` gains `stacklevel=2` on a `warn()` call, so the warning now points at the caller instead of at the logging module — a small but real change in what the user sees. And `plugins.py` has its `%`-formatted plugin warning turned into an f-string, which produces the same text. The remaining nine are ordinary rewrites: a set comprehension instead of `set()` around a generator, a bare function reference instead of a lambda that only forwarded to it, a list comprehension instead of `map()` with a lambda, `[*initial, current]` instead of `initial + [current]`, `list(range(...))` instead of a comprehension over it, and `{}` instead of `dict()`. `is_supported_file` is a classmethod, so dropping the lambda around it keeps the same object, and nothing in the code base shadows `dict`. What is left needs judgement, not a tool: 78 G004 (f-strings in logging calls, which evaluate even when the level discards them), 12 PLR0917, 10 D205, 6 S101 and a handful of others.
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.
Picks up the 110 findings #282 left behind because they need
--unsafe-fixes. Ruff calls them unsafe where a fix can alter meaning rather than only layout, so each was read rather than trusted.audible --helpchangesTwo thirds of the fixes are
D415, a full stop at the end of a docstring's first line. Fifteen of those docstrings belong to click commands, which use them as help text:activation-bytesalready ended in a full stop, so this makes the list consistent rather than changing its style. Compared before and after on the real CLI; the added stop is the only difference.Whitespace inside strings
W291/W293strip trailing whitespace, which Ruff marks unsafe because whitespace inside a string is content. 24 of these lines are exactly that — the quickstart intro, two click help texts and several docstrings.None of it shows. The intro goes to
secho()unchanged and a space before a line break is invisible in a terminal; click rewraps help text regardless.audible api --helpdiffers only by the added full stop, confirmed by diffing the output.Two that are neither cosmetic nor a rewrite
_logging.pygainsstacklevel=2on awarn()call, so the warning points at the caller instead of at the logging module. Small, but a real change in what the user sees — and the reason the rule exists.plugins.pyhas its%-formatted plugin warning turned into an f-string. Same text.Nine ordinary rewrites
A set comprehension instead of
set()around a generator, a bare function reference instead of a lambda that only forwarded to it, a list comprehension instead ofmap()with a lambda,[*initial, current]instead ofinitial + [current],list(range(...))instead of a comprehension over it, and{}instead ofdict().is_supported_fileis a classmethod, so dropping the lambda keeps the same behaviour, and nothing in the code base shadowsdict.What is left
121 findings that need judgement rather than a tool: 78 G004 (f-strings in logging calls, which are evaluated even when the level discards them), 12
PLR0917, 10D205, 6S101and a handful of others. G004 is the obvious next piece and deserves its own pass.Verified
ruff check .andruff format --check .pass, 56 tests green, and against the live APIlibrary list --resolve-podcasts --start-date 2008-01-01returns the identical result set on this branch and on master in the same window — 918 lines, sorted diff empty.