Skip to content

style: apply Ruff's safe autofixes - #282

Merged
mkb79 merged 1 commit into
masterfrom
ci/ruff-autofixes
Aug 7, 2026
Merged

style: apply Ruff's safe autofixes#282
mkb79 merged 1 commit into
masterfrom
ci/ruff-autofixes

Conversation

@mkb79

@mkb79 mkb79 commented Aug 7, 2026

Copy link
Copy Markdown
Owner

The baseline from #281 recorded 442 findings. Ruff can fix 219 of them itself without changing behaviour, so this applies them and shrinks the baseline accordingly.

before after
findings 442 230
file/rule pairs pinned in the baseline 168 75
files with findings 29 23

What went

23 rules disappear completely:

  • Type annotation modernizationUP045 (42), UP007 (31), UP006 (25). Optional[str]str | None, List[x]list[x]. The project already targets py311, so this is catching up with its own target-version.
  • Import sortingI001 (18)
  • Docstring formattingD403 (14), D212 (8), D202 (7), D416 (4), D209 (3), D201 (1)
  • Quote styleQ000 (9)
  • Redundant constructsF541 (3), RUF010 (2), UP015 (2), UP025 (2), UP034 (2), plus one each of UP009, UP032, UP035 (8), PLR5501, RUF021, RUF022, RUF100 (4)

Partially reduced: G004 79→78, W291 30→24, W293 18→6, PGH004 6→3.

What stayed

The remaining 230 are dominated by G004 (78 f-strings in logging calls), D415 (60 docstring endings) and W291 (24 trailing whitespace). Ruff will not fix those on its own.

No --unsafe-fixes. Those 109 can change behaviour and deserve reading one by one, so they are untouched.

Note on the process

The baseline suppresses exactly the findings --fix is meant to repair, so it was removed for the run and regenerated from what remained afterwards.

ruff check --fix reorders imports, which left src/audible_cli/__init__.py unformatted although it had been clean. It is formatted here and dropped from the formatter's exclude list.

pyi_entrypoint.py is included — it sits in the repository root and the release build uses it. Its change is a single quote style swap.

Verified

  • ruff check . and ruff format --check . pass, 56 tests green
  • against the live API, library list --resolve-podcasts --start-date 2008-01-01 returns the identical result set on this branch and on master when run in the same window — 918 lines, sorted diff empty
  • the annotation rewrites are safe here: nothing evaluates annotations at runtime, no get_type_hints, dataclasses or Pydantic in play, and the project requires Python ≥3.11 where X | None is valid at definition time

The baseline added with #281 recorded 442 findings. 219 of them Ruff can fix
on its own without changing behaviour, so this applies them and shrinks the
baseline accordingly.

Fully gone, 23 rules: the type annotation modernization the project's own
target-version already implies (UP006/UP007/UP045, 98 findings), import
sorting (I001), docstring formatting (D2xx/D4xx), quote style (Q000),
redundant f-strings and conversions (F541, RUF010), and a handful of one-off
simplifications (UP009, UP015, UP025, UP032, UP034, UP035, PLR5501, RUF021,
RUF022, RUF100).

  442 findings  ->  230
  168 file/rule pairs in the baseline  ->  75
  29 files with findings  ->  23

Nothing was fixed with --unsafe-fixes; those 109 remain untouched because
they can change behaviour and deserve to be read one by one.

`ruff check --fix` reorders imports, which left `src/audible_cli/__init__.py`
unformatted even though it had been clean. It is formatted here and dropped
from the formatter's exclude list.

The remainder is dominated by G004 (78 f-strings in logging calls), D415 (60
docstring endings) and W291 (24 trailing whitespace), none of which Ruff will
fix on its own.
@mkb79
mkb79 merged commit 22c28b8 into master Aug 7, 2026
7 checks passed
@mkb79
mkb79 deleted the ci/ruff-autofixes branch August 7, 2026 20:50
mkb79 added a commit that referenced this pull request Aug 8, 2026
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.
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