unused suppression for `type: ignore`
https://github.com/astral-sh/ruff/pull/17305 revealed an interesting case where Red Knot raised an unused suppression diagnostic when the user intended to suppress it:
text_encoding = (
io.text_encoding # type: ignore[unused-ignore, attr-defined]
if sys.version_info > (3, 10)
else _text_encoding
)
Source: https://github.com/jaraco/zipp/blob/main/zipp/compat/py310.py
type: ignore currently acts as a wildcard suppression (we disregard anything coming in [...]) and suppresses anything except unused suppression issues. The result is that users aren't able to suppress unused suppression diagnostics with type: ignore and are forced to use a red knot specific suppression instead.
Different options are:
- Change
type: ignoreto suppress all diagnostics (including unused suppression) - Accept that users have to use a red knot specific suppression for unused suppression diagnostics (this is what Ruff does)
- Add support for
type: ignore[unused-ignore] - ..?
I think asking users to use ty: ignore[unused-ignore-comment] seems reasonable.
An alternative to this is to introduce a separate rule for unused type: ignore comments, which a user could disable.