Is your feature request related to a problem?
pyrefly suppress --remove-unused (and pyrefly check --remove-unused-ignores) removes unused # pyrefly: ignore comments, but it does not touch unused # type: ignore comments, even though Pyrefly honors # type: ignore as a valid suppression.
This means that after I clean up my suppressions, any stale # type: ignore comments are left behind and I have to find and delete them by hand. For a large codebase that adopted # type: ignore (for example, coming from another type checker), there is no convenient way to clean these up with Pyrefly.
I understand the default likely excludes # type: ignore on purpose, since those comments are shared with other type checkers and removing them could affect another tool. So I am not asking to change the default behavior.
Describe the solution you'd like
Add an opt-in flag that also removes unused # type: ignore comments:
pyrefly suppress --remove-unused-type-ignores
pyrefly check --remove-unused-type-ignores
This would work like the existing --remove-unused / --remove-unused-ignores, but additionally clean up # type: ignore comments that are not suppressing anything. Users who share # type: ignore with other tools simply would not pass the flag, so the default stays safe.
Reproduction of current behavior
Given a file where every suppression is unused (no error on the line):
a = 1 # pyrefly: ignore
b = 2 # type: ignore
Running pyrefly suppress --remove-unused removes only the first:
a = 1
b = 2 # type: ignore
There is currently no flag that would also remove the unused # type: ignore.
Additional context
The documentation for --remove-unused describes it only in terms of # pyrefly: ignore comments and does not mention # type: ignore handling, so it would be worth documenting the new flag and the default behavior together.
Related
Is your feature request related to a problem?
pyrefly suppress --remove-unused(andpyrefly check --remove-unused-ignores) removes unused# pyrefly: ignorecomments, but it does not touch unused# type: ignorecomments, even though Pyrefly honors# type: ignoreas a valid suppression.This means that after I clean up my suppressions, any stale
# type: ignorecomments are left behind and I have to find and delete them by hand. For a large codebase that adopted# type: ignore(for example, coming from another type checker), there is no convenient way to clean these up with Pyrefly.I understand the default likely excludes
# type: ignoreon purpose, since those comments are shared with other type checkers and removing them could affect another tool. So I am not asking to change the default behavior.Describe the solution you'd like
Add an opt-in flag that also removes unused
# type: ignorecomments:pyrefly suppress --remove-unused-type-ignorespyrefly check --remove-unused-type-ignoresThis would work like the existing
--remove-unused/--remove-unused-ignores, but additionally clean up# type: ignorecomments that are not suppressing anything. Users who share# type: ignorewith other tools simply would not pass the flag, so the default stays safe.Reproduction of current behavior
Given a file where every suppression is unused (no error on the line):
Running
pyrefly suppress --remove-unusedremoves only the first:There is currently no flag that would also remove the unused
# type: ignore.Additional context
The documentation for
--remove-unuseddescribes it only in terms of# pyrefly: ignorecomments and does not mention# type: ignorehandling, so it would be worth documenting the new flag and the default behavior together.Related
# type: ignorecomment #3766