Skip to content

Allow whole file error suppressions for specific kinds. - #3983

Closed
nascheme wants to merge 1 commit into
meta:mainfrom
nascheme:whole-file-suppress-error
Closed

nascheme wants to merge 1 commit into
meta:mainfrom
nascheme:whole-file-suppress-error

Conversation

@nascheme

@nascheme nascheme commented Jun 30, 2026 •

Copy link
Copy Markdown

Summary

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.

My use case for this is that I'm gradually increasing pyrefly's strictness. I want to turn on errors like this:

implicit-any-parameter = "error"       # unannotated function parameters
implicit-any-type-argument = "error"   # bare `list` / `dict` (no type args)
implicit-any-empty-container = "error" # `x = []` with no annotation

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 the testcase! 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:

  • test_pyrefly_top_level_ignore_specific_kind — suppresses a single kind (bad-assignment) and verifies that an unlisted kind (bad-return) still reports. The bad-assignment line has no # E:, while the return "oops" line carries a # E: annotation, proving suppression is kind-scoped rather than whole-file.
  • test_pyrefly_top_level_ignore_specific_kinds_one_line — two kinds comma-separated in one comment ([bad-assignment, bad-return]); both errors are suppressed (no annotations).
  • test_pyrefly_top_level_ignore_specific_kinds_multiline — the same two kinds split across two separate ignore-errors lines, verifying that the lists accumulate.

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

cargo test -p pyrefly suppression

Result: 78 passed, 0 failed (the full suppression suite, including the three new tests).

Note: Claude Opus 4.8 assisted with writing this PR.

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
@rchen152

rchen152 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Sorry for the lack of review - looks like this PR slipped through the cracks. I'll take a look on Monday.

@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@rchen152 has imported this pull request. If you are a Meta employee, you can view this in D115517177. (Because this pull request was imported automatically, there will not be any future comments.)

@rchen152

Copy link
Copy Markdown
Contributor

Actually, this was already implemented in #3944.

@rchen152 rchen152 closed this Aug 11, 2026
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.

2 participants