Add opt-in --remove-unused-type-ignores flag#3990
Open
nitishagar wants to merge 1 commit into
Open
Conversation
Summary: suppress --remove-unused and check --remove-unused-ignores remove unused # pyrefly: ignore comments but leave unused # type: ignore comments behind, even though Pyrefly already detects them as unused. Add an opt-in --remove-unused-type-ignores flag (on both check and suppress) that additionally removes unused # type: ignore comments. It is off by default, so # type: ignore comments (which are shared with other type checkers) are never removed unless explicitly requested. The flag threads a remove_type_ignores boolean into the existing removal path and adds a gated arm to the message-prefix decision that handles the UnusedTypeIgnore errors Pyrefly already produces. Fixes facebook#3984 Test Plan: cargo build -p pyrefly; cargo test -p pyrefly remove_unused (23 passed); cargo clippy -p pyrefly --tests; manual repro from the issue - with the flag both # pyrefly: ignore and unused # type: ignore are removed, without the flag only the pyrefly one is removed.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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
pyrefly suppress --remove-unusedandpyrefly check --remove-unused-ignoresremove unused# pyrefly: ignorecomments, but they leave unused# type: ignorecomments behind — even though Pyrefly honors# type: ignoreand already detects when one is unused. After cleaning up suppressions, any stale# type: ignorecomments have to be found and deleted by hand, which is painful in codebases that adopted# type: ignore(e.g. coming from another type checker).This adds an opt-in
--remove-unused-type-ignoresflag (on bothcheckandsuppress) that additionally removes unused# type: ignorecomments, working just like the existing--remove-unused/--remove-unused-ignoresflags. It is off by default, so# type: ignorecomments — which are shared with other type checkers — are never touched unless the flag is explicitly passed.The change threads a
remove_type_ignoresboolean into the existing removal path and adds a single gated arm that handles theUnusedTypeIgnoreerrors Pyrefly already produces; unused detection is unchanged.Fixes #3984.
Test plan
cargo build -p pyreflycargo test -p pyrefly remove_unused— 23 passed, including newtest_remove_unused_type_ignore_inline/test_remove_unused_type_ignore_with_codeand a regression test asserting the comment is kept when the flag is absent.cargo clippy -p pyrefly --tests