`# type: ignore` does not support specific error codes
Describe the Bug
Because pyrefly appears to be only looking for # type: ignore, it does not support ignore specific error codes. The follow succeeds with no errors.
def func(x: int) -> None:
print(x)
func(x="hello", y=3) # type: ignore[this-is-not-a-real-error]
This can be a little problematic for migrating code bases. The # type: ignore becomes a blanket ignore, potentially hiding other errors like in my example.
One approach is to only accept specific error codes if prefixed with pyrefly: like ty does. Here is an example of mypy and ty coexisting with suppressions using # type: ignore. Note that this only works if unused-ignore is disabled in mypy.
def func(x: int) -> None:
print(x)
func(x="hello", y=3) # type: ignore[call-arg, arg-type, ty:unknown-argument, ty:invalid-argument-type]
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSImMYABGAK7oDGAFPojROgC4CUNAWgB8NAHK50MRAB10NeTWIAnLtza9ZDZmwC80kAAsYUKLn0AaGqR0BmfjQDENbqWJTOAc3S4lMANrcBhBwAsEC3twCqAK%2BqFACMEpKPgC6IOYgZL5gUKSE3LgAtlAUTgAKpNm5NGhYePg0TBKQHvRKqNwQEoSyTgDKMDA0BtzcxHCIAPSTWdS5hD4ekzDok5i4THCTTegtbR1dq3Q%2BNKgAbqjQqNiwjc0Qre2dEjS4xM-ocD3oZIESAmdEnBDjQdDR9DZCABGABM%2BlkyngMG4oPBIDg3BUTG48PQIAAvhlUNiIICAGLQGAUWo4Agkcj4oA
(Only applicable for extension issues) IDE Information
No response
Sounds like a reasonable addition
I can take this.
Planned approach:
- keep bare
# type: ignoreas a blanket suppression for PEP 484 compatibility; - when
# type: ignore[...]has codes, only suppress Pyrefly diagnostics for entries explicitly prefixed aspyrefly:<error-code>; - leave
# pyrefly: ignore[...]unchanged; - add regression tests for an invalid
# type: ignore[...]code that should not hide Pyrefly errors, plus apyrefly:<code>case that should.
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
Still active via #3860. I revalidated the PR locally on 2026-07-17 with the focused ignore parser tests, suppression integration tests, formatting, diff whitespace check, and the repo no-test lint/format wrapper using the GNU Rust toolchain. Public CI is green; the remaining blocker appears to be Meta's internal Import Status queue.
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
Still active via #3860. The branch has been refreshed and revalidated; Ubuntu, macOS, Meta internal checks, mypy_primer, and all auxiliary checks are green. The sole failing Windows check is the known flaky LSP test test_stream_diagnostics_no_flicker_after_undo_edit, which also failed on main at the same assertion; I have asked a maintainer to rerun that job because external contributors cannot do so.
Still active via #3860. I refreshed the branch onto current main today, resolved its tensor-shapes conflict without changing the reviewed behavior, and reran the focused parser/suppression tests plus the repository format-and-Clippy wrapper successfully. The PR is conflict-free and CI has restarted on head b84b61c70.