[flake8-pyi] Extend PYI033 to Python files in preview#26129
Merged
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| type-comment-in-stub | 28 | 28 | 0 | 0 | 0 |
Member
Author
|
All the ecosystem hits look like true positives to me |
ntBre
approved these changes
Jun 18, 2026
Contributor
I guess we might need to rename the rule eventually? |
Member
Do we need to change the rule name (This is not a breaking change yet) |
Member
Author
|
Shoot, I merged before seeing your comments. I'll rename it in a followup. |
Member
|
Renaming in a follow up seems preferred anyway :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR revives #4166.
There's no reason to use type comments in modern Python code. I'd argue they're effectively soft-deprecated at this point, and they're entirely unsupported by modern type checkers such as ty and pyrefly. In the three years since the last PR proposing this change, Python 2 has become much less widely used in the ecosystem, and many other flake8-pyi rules have been extended so that they now run on
.pyfiles as well.If you enable strict mode in pyright, it enables pyright's
reportTypeCommentUsagerule, which bans the use of type comments. I don't want to have to reimplement that rule in ty for pyright parity, when we already have a very good implementation over here in Ruff ;)#1619 (comment) pointed out that there are still uses for type comments for things like
forloops, e.g.But even here, while it's not quite as pretty, mypy users can easily use modern type annotations instead:
Closes #4460