Skip to content

Adopt ruff for linting and formatting - #233

Open
kroenlein wants to merge 2 commits into
mainfrom
ruff-migration
Open

Adopt ruff for linting and formatting#233
kroenlein wants to merge 2 commits into
mainfrom
ruff-migration

Conversation

@kroenlein

@kroenlein kroenlein commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

No-op PR that updates formatting so that it confirms to both ruff and flake8.

kroenlein and others added 2 commits September 10, 2026 15:20
Add a [tool.ruff] configuration to pyproject.toml, then apply ruff's lint
fixes and formatter across gemd and tests. tox.ini keeps the flake8 rules
unchanged, so both linters run green on the same tree.

The result is stable under editor-on-save: `ruff check --fix` and
`ruff format` each make no further changes.

The config mirrors flake8 wherever flake8 has an opinion. It selects E, W,
F and D to match pycodestyle, pyflakes and flake8-docstrings, and names
E231 and E275 individually because ruff still treats those two as preview
rules. It adds isort, which flake8 never checked. Where flake8 is silent,
it follows ruff's defaults, so the pydocstyle convention stays unset and 15
more D rules apply than flake8 enforced.

Hand-fix the places where the formatter's output broke a flake8 rule.
pycodestyle exempts backslash continuations from W503, and the formatter
rewrites those continuations as parentheses, so eight long boolean
conditions needed restructuring into named intermediate values. Two slices
in gemd/units/impl.py get their bounds hoisted into locals, which keeps the
formatter from spacing the colon (E203). One TypeVar call is exploded so
its trailing noqa comment fits inside 99 characters, because the formatter
excludes such comments when measuring width and flake8 counts them.

Fix two real defects the wider rule set exposed. tests/builders used
BaseValue in annotations without importing it. The parameter type in
BaseTemplate._homogenize_ranges wrapped across two lines, which hid its
description from the numpy-section parser and from Sphinx.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rewrite every str.format call site in gemd and tests as an f-string. The
rendered strings are unchanged, since both forms dispatch to __format__.

Ruff's UP032 rule generated 44 of these. It skipped two call sites, which
this commit rewrites by hand: each nested a double-quoted string inside its
format arguments, and an f-string expression cannot reuse the enclosing
quote character before Python 3.12. Both now use single quotes inside the
expression, which Python 3.9 accepts.

Leave UP032 out of the ruff rule selection. This is a one-time improvement
rather than a standing rule.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kroenlein
kroenlein marked this pull request as ready for review September 10, 2026 21:36
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