Skip to content

Expand PGH003 / create another rule to only allow # pyright: ignore[diagnosticRuleName] comments #13532

Open
@kkom

Description

blanket-type-ignore bans blanket # type: ignore comments, however that's not entirely helpful for Pyright users.

The docs suggest to use # type: ignore[diagnosticRuleName] instead, which Pyright sadly doesn't understand – it only accepts # pyright: ignore[diagnosticRuleName]

Would it be possible to expand this rule / create another one to only allow # pyright: ignore[diagnosticRuleName] comments?

Pyright materials on # type: ignore vs # pyright: ignore

microsoft/pyright#2877 (comment)

https://github.com/microsoft/pyright/blob/main/docs/comments.md#line-level-diagnostic-suppression

Example

Incorrect diagnostic rule caught by Pyright:

Screenshot 2024-09-27 at 10 22 41

# type: ignore[ruleThatDoesNotExist] interpreted as # type: ignore by Pyright:

Screenshot 2024-09-27 at 10 22 51

Activity

kkom

kkom commented on Sep 27, 2024

@kkom
Author

I guess we could have two rules:

One that bans blanket type ignore comments (regardless of whether it's the vanilla or pyright one) -- the one I referred to could be expanded like this

Another that bans the vanilla "type: ignore" comment, in favour of the pyright version -- that would need to be new I think

That is, if you're happy to have some Pyright specific rules in Ruff!

MichaReiser

MichaReiser commented on Sep 28, 2024

@MichaReiser
Member

Extending blanked-type-ignore to also lint for pyright: ignore without a rule code seems reasonable.

Another that bans the vanilla "type: ignore" comment, in favour of the pyright version -- that would need to be new I think

Isn't this covered by by using a combination of blanked-type-ignore (which flags all blank ignore codes) and running pyright (which flags a type error everywhere where someone uses type: ignore[code])? Or does pyright ignore all codes when using type: ignore[code]?

kkom

kkom commented on Sep 28, 2024

@kkom
Author

Yeah, the problem is that Pyright treats both of these as a blanket ignore:

  • type: ignore
  • type: ignore[whateverTextHere]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    configurationRelated to settings and configurationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Expand PGH003 / create another rule to only allow `# pyright: ignore[diagnosticRuleName]` comments · Issue #13532 · astral-sh/ruff