Skip to content

unused suppression for type: ignore #130

@MichaReiser

Description

@MichaReiser

astral-sh/ruff#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: ignore to 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]
  • ..?

Metadata

Metadata

Assignees

No one assigned

    Labels

    suppressionRelated to supression of violations e.g. ty:ignore

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions