-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Enable ruff's isort rules on files generated using mypy-protobuf #10939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_file But 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!