最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to check if `pyright: ignore` comments are still required? - Stack Overflow

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论