microsoft / pyright

Static Type Checker for Python
Other
13.24k stars 1.43k forks source link

Provide an option to disallow `pyright: ignore` comments without explicit rule categories #9184

Closed Bruntaz closed 2 days ago

Bruntaz commented 2 days ago

Is your feature request related to a problem? Please describe. Pyright supports 3 types of 'ignore' comment:

There is an option to disallow type: ignore comments to force the Pyright-specific comment-style, but if a project exclusively uses Pyright, there's not really a benefit to use pyright: over type:. Both styles of ignore have the potential to hide more problems than the developer intended. For example, I wrote this code earlier:

from lxml.etree import Element, SubElement, _Element  # pyright: ignore [reportPrivateUsage]  # lxml not designed for type hinting

If I just wrote pyright: ignore, the comment could silence an error about lxml not being installed instead of just hiding the private member import.

In our source base, there are quite a few blanket ignores because they are often ignored/missed in code reviews.

Describe the solution you’d like An option similar to enableTypeIgnoreComments (or a new value to) which only allows the third kind of ignore, where the developer explicitly ignores the error code(s) that Pyright is throwing.

erictraut commented 2 days ago

Thanks for the suggestion, but I'm not convinced such a feature would be useful to enough pyright users. It's not a feature that could be enabled by default, even in strict mode. That means it would suffer from discoverability issues.

This is also arguably more of a linter feature than a type checker feature. Have you looked into writing a custom linter rule? Or perhaps the ruff folks would be willing to add a standard rule for this case.

I'm going to reject this enhancement request. I'm willing to reconsider this decision in the future if there's sufficient signal from other pyright users in the form of thumbs-up reactions.