Skip to content
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

Enable some Ruff TC rules (flake8-type-checking) #13333

Merged
merged 5 commits into from
Jan 2, 2025

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Dec 29, 2024

Ref #13295
https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc

All rules are autofixable

I doubt we'd want to add a bunch if if TYPE_CHECKING blocks in typeshed's scripts (unless we have an explicit reason to do so), so I pre-emptively disabled TC001, TC002 and TC003. The rest seem like useful checks that are not necessarily covered by type-checkers.

@AlexWaygood
Copy link
Member

I'm a little concerned about enabling this whole category because some of the rules in this category are quite opinionated stylistic rules. That might not be an issue for us right now, but it could become an issue in the future if Ruff stabilises an opinionated rule and we don't agree with it.

For this category, I think I'd prefer to just enable the specific rules that we think would be useful for this repository

@Avasam
Copy link
Collaborator Author

Avasam commented Jan 2, 2025

I'm guessing that any rules that moves stuff into a type-checking block, or adds quotes around an annotation are things we're not concerned with, and would rather keep the simplicity of not quoting/extra conditional block

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.

Nice, these three seem reasonable to me!

@AlexWaygood AlexWaygood changed the title Enable Ruff TC (flake8-type-checking) Enable some Ruff TC rules (flake8-type-checking) Jan 2, 2025
@AlexWaygood AlexWaygood merged commit 0cebf26 into python:main Jan 2, 2025
46 checks passed
@Avasam Avasam deleted the Ruff-TC branch January 2, 2025 21:47
@Daverball
Copy link
Contributor

FWIW I try to keep the opinionated stuff from flake8-type-checking out of stub files, since it doesn't really make much sense there, so the only rules that even work in stubs are the ones that are net-wins without drawbacks.

TC005, TC008 and TC010 are as of 0.8.5 the only rules that work in stub files. So you could actually safely enable TC, but it also doesn't hurt to be more selective to signal intent. I just thought I'd mention it, since you currently have TC004 selected, which doesn't actually work in stubs (although it probably could, but the logic would have to be different. If you want it to work feel free to open an issue on ruff's repository and @ me, should be easy to implement).

@Avasam
Copy link
Collaborator Author

Avasam commented Jan 2, 2025

Thanks!

since you currently have TC004 selected, which doesn't actually work in stubs

We also lint our tests and scripts, which have been growing in size and complexity. The Ruff rules we enable are not exclusive to stubs. But we're less strict with the rules we enforce for those.

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.

3 participants