Enable ruff's isort rules on files generated using mypy-protobuf#10939
Enable ruff's isort rules on files generated using mypy-protobuf#10939JelleZijlstra merged 3 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
AlexWaygood
left a comment
There was a problem hiding this comment.
Thanks! The cause here is a merge race between a PR that updated our generated protobuf and tensorflow stubs, and a PR that switched us from using isort to ruff for import sorting.
On the one hand, all these files have isort:skip_file in their module docstrings. It seems obvious why ruff isn't respecting that directive in the same way isort used to!
On the other hand, I don't see a compelling reason to exclude our generated stubs from import sorting, given that pre-commit should apply the fixes automatically when we next update our generated stubs. So I say we go ahead with this!
|
You are right, I didn't see the isort skip until you mentioned it. I did some tests and it appears ruff only respects this line if it is a comment, and not in the docstring: This doesn't work """
isort:skip_file
"""nor this """
# isort:skip_file
"""but this works """
...
"""
# isort:skip_fileBut as you said, there is no compelling reason to skip sorting imports in these files |
|
I think I'll create a stopgap PR to skip running ruff's isort rules on |
Done in #10940. This is now a PR to enable running ruff's isort rules on |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I can also see why it'd be ignored from a docstring, could be worth raising the deviation to be documented in https://docs.astral.sh/ruff/linter/#action-comments |
Originally opened to stop pre-commit-ci fixing other unrelated PRs due to https://results.pre-commit.ci/run/github/31696383/1698462880.Wm4kIn7fRrmhF3zdHHVXvg of #10912.
The issue was then fixed in #10940 (thanks Alex). This is now a PR to enable running ruff's isort rules on *_pb2.pyi files!