Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@riga
Copy link
Collaborator

@riga riga commented May 9, 2025

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

  • PLC0415, to allow inline imports,
  • PLW3201, to allow defining custom dunder methods like __treescope_repr__, and
  • RUF052, to allow using variable names that match the so-called "dummy pattern" with a leading underscore, i.e. _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 the float ↔︎ Array mismatch.

This won't fix in the future (in fact, this typing ambiguity was a reason why the built-in dataclasses.field did not get the converter feature, see the rejected PEP712), so in a different PR I would add exclusions for the relevant lines (#49).

@riga riga mentioned this pull request May 9, 2025
@pfackeldey
Copy link
Owner

Thanks 🎉 this looks good!

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 the float ↔︎ Array mismatch.

Good point. I'll try to figure out if there's anything we can do about it 👍

@pfackeldey pfackeldey merged commit cd61136 into pfackeldey:main May 9, 2025
6 checks passed
@riga riga deleted the feat/ruff_preview branch May 9, 2025 12:52
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.

2 participants