Skip to content

[ty] Add blanket ignore comment rule - #26426

Merged
MichaReiser merged 13 commits into
mainfrom
micha/ty-blanket-ignore-comments
Jul 8, 2026
Merged

[ty] Add blanket ignore comment rule#26426
MichaReiser merged 13 commits into
mainfrom
micha/ty-blanket-ignore-comments

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary

Adds an opt-in blanket-ignore-comment rule that requires rule codes on ty: ignore comments.

Closes astral-sh/ty#3324.

Test Plan

Testing: Added mdtest coverage and ran the ty semantic test suite, Clippy, and repository hooks.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 27, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.54%. The percentage of expected errors that received a diagnostic held steady at 90.31%. The number of fully passing files held steady at 96/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jun 27, 2026
@MichaReiser
MichaReiser marked this pull request as ready for review July 5, 2026 16:22
@MichaReiser
MichaReiser requested review from a team as code owners July 5, 2026 16:22
@astral-sh-bot
astral-sh-bot Bot requested a review from carljm July 5, 2026 16:22

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I would like to better understand the rationale for some of the design choices here, left comments inline.

I also think the interaction between this rule and --add-ignore should at least be explicitly documented and tested. The current interaction is a bit strange, in that --add-ignore will change:

value = missing  # ty: ignore

into

value = missing  # ty: ignore  # ty: ignore[blanket-ignore-comment]

Which feels a bit strange, but might actually be the most straightforward and intuitive option?

Comment thread crates/ty_python_semantic/src/suppression.rs Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/suppressions/blanket_ignore.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/suppressions/blanket_ignore.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/suppressions/blanket_ignore.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/suppressions/blanket_ignore.md Outdated
@MichaReiser

Copy link
Copy Markdown
Member Author

Regarding --add-ignore. We could decide to never add an ignore for blanked-ignore. That's what we do for unused-ignore comment. Although this seems non ideal. The alternative is to fix the ignore comment by adding the specific code. That would certainly be nice but is also more work than I think this rule is currently worth it. So I'd suggest we ship this improvement separately.

@MichaReiser
MichaReiser force-pushed the micha/ty-blanket-ignore-comments branch from 6af7fdf to 971eed5 Compare July 7, 2026 07:00
@MichaReiser
MichaReiser requested a review from carljm July 7, 2026 07:37

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Comment thread crates/ty_python_semantic/resources/mdtest/suppressions/blanket_ignore.md Outdated
@MichaReiser

MichaReiser commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Having thought about this again, I actually think what I had before was better. Maybe not in this every exact form but raising a blanket-ignore-comment warning AND unused-ignore-comment just feels unnecessarily noisy. The right fix is always to remove the unused ignore comment. The blanked ignore comment warning is just noise and not helpful for users.

However, we should report any blanked ignore comment if unused-ignore-comment is disabled.

The current design is also unfavorable to --fix and --add-ignore. Running --add-ignore on:

value = 1  # ty: ignore

First produces

value = 1  # ty: ignore  # ty:ignore[blanket-ignore-comment]

If you now run --fix, ty has to iterate twice:

  1. To remove the ty: ignore, which is unused
  2. To remove the now unused # ty:ignore[blanket-ignore-comment] comment

@MichaReiser
MichaReiser requested a review from carljm July 8, 2026 07:21
@carljm

carljm commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Sorry, I still strongly disagree here. I think it is confusing for different rules to interact in this way and silence each other. Each rule should have simple documented rules for what causes it to fire, and follow those rules, independent of other rules, even if that results in two diagnostics on one line.

It is not necessarily the case that "The right fix is always to remove the unused ignore comment." -- that's an unwarranted assumption that is trying too hard to read the user's mind. This is up to the user to decide. They've asked us to error on blanket ignores, and we should do that.

Consider the case where the configuration specifies blanket-ignore-comment = "error" and unused-ignore-comment = "warn". The user has requested that every blanket ignore comment should be a diagnostic of "error" severity. It is a bug if they have a blanket ignore comment, and we only issue a diagnostic of "warn" severity on that line.

@MichaReiser

MichaReiser commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

It is not necessarily the case that "The right fix is always to remove the unused ignore comment." -- that's an unwarranted assumption that is trying too hard to read the user's mind. This is up to the user to decide. They've asked us to error on blanket ignores, and we should do that.

That would imply that --fix doesn't do what the user intended or that it's not a safe fix. Both outcomes don't feel desirable to me.

Consider the case where the configuration specifies blanket-ignore-comment = "error" and unused-ignore-comment = "warn"

Fix also doesn't make this distinction.

@carljm

carljm commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

I think it is reasonable for --fix to assume that the right fix for an unused ignore comment is to remove it, and that still doesn't imply that we should silence other diagnostics that the user has asked for, related to that ignore comment.

I don't think that whether --fix distinguishes between warnings and errors is relevant to the case I mentioned. --fix isn't the only use case for diagnostics. If the user has asked for an error diagnostic for a certain condition, then we should emit an error diagnostic when that condition applies.

@MichaReiser

Copy link
Copy Markdown
Member Author

The error/warning case is interesting. But I still think raising unused-ignore-comment is the more accurate diagnostic than raising both. We also apply similar heuristics in ty. E.g. we prefer duplicate-base over raising inconsistent-mro, because it's the more accurate diagnostic

@carljm

carljm commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

IMO those cases are not parallel. duplicate-base is effectively a more specific variant of inconsistent-mro. unused-ignore-comment and blanket-ignore-comment are totally orthogonal conditions: neither one is a more specific variant of the other. An ignore comment can be both unused and blanket, or it can be one or the other, or neither.

@MichaReiser

Copy link
Copy Markdown
Member Author

I don't fully agree, but it seems you feel more strongly about this than I. So I'll back out of my last change for now, so that this gets merged (and I can put it behind me :))

@MichaReiser
MichaReiser force-pushed the micha/ty-blanket-ignore-comments branch from e784e32 to 6f985de Compare July 8, 2026 19:23
@MichaReiser
MichaReiser enabled auto-merge (squash) July 8, 2026 19:23
@MichaReiser
MichaReiser merged commit 66b978e into main Jul 8, 2026
62 checks passed
@MichaReiser
MichaReiser deleted the micha/ty-blanket-ignore-comments branch July 8, 2026 19:29
@AlexWaygood

Copy link
Copy Markdown
Member

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

Labels

rule Implementing or modifying a lint rule ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallow blanket ty:ignore

3 participants