Add unused-type-ignore rule#3784
Open
aodihis wants to merge 4 commits into
Open
Conversation
* Projects using multiple type checkers put `# type: ignore` for mypy without wanting pyrefly to flag them, so this rule is a separate opt-in (off by default) distinct from the existing `unused-ignore` rule which covers `# pyrefly: ignore` comments * Added `UnusedTypeIgnore` error kind with `Severity::Ignore` default; extended `collect_unused_ignore_errors` to detect `Tool::Type` suppressions that cover no pyrefly errors on their line, treating any mypy-style codes as blanket since they are not pyrefly codes * Fixed `collect_unused_ignore_errors_for_display` to look up severity by each error's own kind rather than hardcoding `UnusedIgnore`, so the two rules can be configured independently * Added three unit tests and documented the new rule in error-kinds.mdx
* Mirrors the existing unused-ignore LSP test pattern with two tests: one verifying the diagnostic appears when the rule is enabled in config, and one verifying it is silent by default (off-by-default behavior)
yangdanny97
reviewed
Jun 12, 2026
| continue; | ||
| } | ||
|
|
||
| // For Tool::Type (`# type: ignore`), codes are mypy codes (not pyrefly |
Contributor
There was a problem hiding this comment.
codes are mypy codes
I'm not sure this is true, I don't think type: ignore as written in the typing spec has official codes
that said, if someone does use it with a code we proabbly can't shouldn't assume we understand it
Author
There was a problem hiding this comment.
I see, sure, I will remove these unnecessary comments.
Contributor
|
I would have thought we could use simpler tests for this, but I checked and the other unused-ignore is tested the same way. I think this is fine for now. This can probably be merged after some editing of the comments @NathanTempest |
* Replace inaccurate "mypy codes" description with a simpler statement of the actual behavior
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
Adds a new
unused-type-ignorerule that reports# type: ignorecomments that are not suppressing any error.Fixes #3766
This rule is off by default to avoid breaking projects using multiple type checkers (e.g. mypy + pyrefly). Enable it in
pyrefly.toml:Test Plan