Python linter in vscode 类型检查不完整(预期...得到...)

Python linter in vscode with incomplete type checking (Expected... got...)

我使用 vscode,我发现 Python linter(s)不检测何时使用与签名定义不同类型的参数调用 python 函数。

在这种情况下,函数需要 typing.Type[Exception] 而不是 Exception:

Pycharm检测到这种情况:

我认为 mypy 没有检测到这个,因为它使用了 typing 模块(mypy 检测到内置类型中的类型不匹配)。

注意:我遵循了此 SO (--check-untyped-defs) 中的标志建议,但它没有用。

按照评论部分的建议,我在 vscode 中通过以下方式完成了此操作:

  1. 正在安装 Pylance plugin
  2. 在用户设置中设置以下参数:
    "python.languageServer": "Pylance",
    "python.analysis.typeCheckingMode": "strict",