admin管理员组

文章数量:1391982

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: ).

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.

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/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.

Share Improve this question edited Mar 12 at 18:17 InSync 11.1k4 gold badges18 silver badges56 bronze badges asked Mar 12 at 17:27 Ben JeffreyBen Jeffrey 98312 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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".

本文标签: pythonHow to check if pyright ignore comments are still requiredStack Overflow