Skip to content

feat(suppress): add --remove-unused-type-ignores flag#4200

Open
tobyh-canva wants to merge 3 commits into
facebook:mainfrom
tobyh-canva:feat/suppress-remove-unused-type-ignores
Open

feat(suppress): add --remove-unused-type-ignores flag#4200
tobyh-canva wants to merge 3 commits into
facebook:mainfrom
tobyh-canva:feat/suppress-remove-unused-type-ignores

Conversation

@tobyh-canva

@tobyh-canva tobyh-canva commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the --remove-unused-type-ignores flag to pyrefly suppress and pyrefly check, which removes # type: ignore comments in addition to # pyrefly: ignore comments.

Resolves #3984.

Comment on lines +582 to +585
pub fn remove_unused_ignores_from_serialized(
unused_ignore_errors: Vec<SerializedError>,
remove_unused_type_ignores: bool,
) -> usize {

@tobyh-canva tobyh-canva Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is getting a bit unwieldy and I think the way ignore removal works might deserve a refactor in a future PR.

The type-checker flags an unused ignore, then the suppressor has to work backwards from the human-readable error message and parse the line with regex to discover which parts of the line to remove. The type-checker could instead record the precise information once when flagging the error, serialise it in a structured way, then the suppressor just does the rudimentary cleanup.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/l and removed size/l labels Jul 18, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/l and removed size/l labels Jul 18, 2026
@tobyh-canva
tobyh-canva marked this pull request as ready for review July 18, 2026 08:45
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: --remove-unused-type-ignores flag to clean up unused # type: ignore comments

1 participant