Allow whole file error suppressions for specific kinds.#3983
Open
nascheme wants to merge 1 commit into
Open
Conversation
This allows the following comments at the beginning of files:
# pyrefly: ignore-errors[kind, ...]
Multiple kinds can be comma-separated on one line, or split across
several `ignore-errors` lines; the lists accumulate.
Assisted-by: Claude Opus 4.8
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 allows the following comments at the beginning of files:
Multiple kinds can be comma-separated on one line, or split across several
ignore-errorslines; the lists accumulate.My use case for this is that I'm gradually increasing pyrefly's strictness. I want to turn on errors like this:
However, I have many "legacy" Python files that don't conform to this level of strictness. Rather than have many "sub_config" sections or add individual per-line suppressions, I want to suppress these kinds of errors for whole files.
Test Plan
The feature is covered by integration tests in
pyrefly/lib/test/suppression.rs, using thetestcase!macro. Each test is a snippet of Python source with inline error expectations: a# E: <message>comment marks a line where an error is expected, and any line without such a comment must produce no error. The macro type-checks the snippet and asserts that emitted errors match the annotations exactly.Three new tests exercise the
# pyrefly: ignore-errors[kind, ...]syntax:Together these cover the single-kind, comma-separated, and multi-line accumulation paths, and the negative case (an unlisted kind is not suppressed).
Running the tests
Result: 78 passed, 0 failed (the full suppression suite, including the three new tests).
Note: Claude Opus 4.8 assisted with writing this PR.