Skip to content

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

Merged
merged 3 commits into from
Oct 28, 2023

Conversation

hamdanal
Copy link
Contributor

@hamdanal hamdanal commented Oct 28, 2023

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!

@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a 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!

@hamdanal
Copy link
Contributor Author

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

@AlexWaygood
Copy link
Member

I think I'll create a stopgap PR to skip running ruff's isort rules on *_pb2.pyi files, since that preserves the status quo and will stop pre-commit-ci pushing unwelcome "autofixes" to every PR that's filed at typeshed. But let's keep this open since, as I say, there doesn't appear (to me) to be a compelling reason not to sort imports in these files.

@AlexWaygood AlexWaygood changed the title Fix failing lints Enable ruff's isort rules on files generated using mypy-protobuf Oct 28, 2023
@AlexWaygood
Copy link
Member

I think I'll create a stopgap PR to skip running ruff's isort rules on *_pb2.pyi files, since that preserves the status quo and will stop pre-commit-ci pushing unwelcome "autofixes" to every PR that's filed at typeshed. But let's keep this open since, as I say, there doesn't appear (to me) to be a compelling reason not to sort imports in these files.

Done in #10940. This is now a PR to enable running ruff's isort rules on *_pb2.pyi files!

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 6748816 into python:main Oct 28, 2023
@hamdanal hamdanal deleted the fix-pre-commit branch October 28, 2023 14:35
@Avasam
Copy link
Collaborator

Avasam commented Nov 1, 2023

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!

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

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.

4 participants