Conversation
As a first step, this ports all of our existing flake8 rules to Ruff. I have omitted pyupgrade for which Ruff has partial support.
f65c361 to
dd1471d
Compare
|
You beat me (by about a day). I've already started on scikit-build-core and cibuildwheel. :) |
| def test_isolation(tmp_dir, package_test_flit, mocker): | ||
| try: | ||
| import flit_core # noqa: F401 | ||
| import flit_core # noqa: F401 # imported but unused |
There was a problem hiding this comment.
Just curious, would import flit_core as _ work?
There was a problem hiding this comment.
I guess the correct way to do this would be checking importlib.util.find_spec("flit_core") against None.
There was a problem hiding this comment.
Just curious, would
import flit_core as _work?
It does not.
There was a problem hiding this comment.
Could try adding del flit_core to the else-block, then.
There was a problem hiding this comment.
importlib.util.find_spec("flit_core") is the correct solution imo. It’s also faster if the module is large, since you don’t have to load it. Not that important for tests, but nice to do things the right way as a good example.
There was a problem hiding this comment.
And you wouldn’t need an else block for the del. It’s never used, so it could be in the try.
There was a problem hiding this comment.
You'd just need to reference it; flit_core on a new line would be sufficient. I don't think we need to do any of those things however, silencing the warning where it does not apply is perfectly fine.
There was a problem hiding this comment.
@henryiii yep, using importlib is certainly better, but I was suggesting to use the fact that the else-block is already present, w/o much refactoring.
Also, referencing it in the try-section is a code smell because it should always have exactly one instruction.
|
Ruff can also replace pyupgrade (the support is nearly there, only 1-2 fixes not supported - I think it's fine for a continuous check), isort, and the Python parts of the pygrep hooks. No need to do that right now, but would be a good followup. |
As a first step, this ports all of our existing flake8 rules to Ruff. I have omitted pyupgrade for which Ruff has partial support.