feat: Use ruff in preview mode #48
Merged
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.
I noticed that the linting and formatting performed by the current pre-commit sequence is not fully in line with the ruff rules defined in the
pyproject.toml. To be able to get live feedback from ruff while typing, preview mode needs to be activated, adding additional rules that are not yet part of the main linting pass. Except for three of these additional rules, ruff is now fully compatible to the pre-commit workflow.In detail, I disabled
__treescope_repr__, and_VARNAME.The additional rules highlighted only a single extra issue (unused variable) that I fixed.
With the new settings, mypy now also works properly on all staged diffs as intended.
Side note: In my local setup that runs type checks on the full code base, I see a couple issues raised regarding mypy not being able interpret the output type of eqx's
attr: Array = eqx.field(converter=...)feature. E.g. pytrees are initialized with members set to floats, without mypy knowing that they will be converted to 1d float arrays and complaining about thefloat↔︎Arraymismatch.This won't fix in the future (in fact, this typing ambiguity was a reason why the built-in
dataclasses.fielddid not get theconverterfeature, see the rejected PEP712), so in a different PR I would add exclusions for the relevant lines (#49).