I have recently switched from using mypy
to pyright
for static type checking. mypy
has a useful feature whereby it can be configured to warn you if it detects comments instructing it to ignore certain errors which would not actually be raised (described here: https://stackoverflow.com/a/65581907/7256443).
Does anyone know if pyright
has a similar feature? I can't see any reference to it in their documentation. Ideally, it would apply to the pyright
specific ignore comments (# pyright: ignore [errorCode]
) as well as the generic # type: ignore
.
Pyright has reportUnnecessaryTypeIgnoreComment
, which flags unnecessary # type: ignore
comments as errors.
To enable this check, add the following to your pyrightconfig.json
:
{
"reportUnnecessaryTypeIgnoreComment": "error"
}
Source:
Pyright Documentation - Type Check Diagnostics Settings
reportUnnecessaryTypeIgnoreComment
[boolean or string, optional]: Generate or suppress diagnostics for a# type: ignore
or# pyright: ignore
comment that would have no effect if removed. The default value for this setting is"none"
.