pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

`# type: ignore` does not support specific error codes

Open dillydill123 opened this issue 5 months ago • 7 comments

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

dillydill123 avatar Jun 14 '26 01:06 dillydill123

Sounds like a reasonable addition

yangdanny97 avatar Jun 15 '26 19:06 yangdanny97

I can take this.

Planned approach:

  • keep bare # type: ignore as a blanket suppression for PEP 484 compatibility;
  • when # type: ignore[...] has codes, only suppress Pyrefly diagnostics for entries explicitly prefixed as pyrefly:<error-code>;
  • leave # pyrefly: ignore[...] unchanged;
  • add regression tests for an invalid # type: ignore[...] code that should not hide Pyrefly errors, plus a pyrefly:<code> case that should.

WilliamK112 avatar Jun 18 '26 06:06 WilliamK112

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!

github-actions[bot] avatar Jul 04 '26 00:07 github-actions[bot]

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.

WilliamK112 avatar Jul 17 '26 06:07 WilliamK112

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!

github-actions[bot] avatar Aug 01 '26 00:08 github-actions[bot]

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.

WilliamK112 avatar Aug 09 '26 13:08 WilliamK112

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.

WilliamK112 avatar Sep 07 '26 15:09 WilliamK112