【问题标题】:Configuring dmypy to check only some files with vscode使用 vscode 配置 dmypy 以仅检查某些文件
【发布时间】:2021-10-10 23:22:18
【问题描述】:

我将 mypy 守护程序与 vscode(和 this extension)一起使用,我希望它只检查我项目中的一些文件。

在我的pyproject.toml 中,我的 mypy 配置如下:

[tool.mypy]
scripts_are_modules = true
show_traceback = true
files = [
    "server/**/*_some_files.py"
]

根据documentation,它应该可以工作,并且期望的行为是应该只检查server 目录下的.py 文件,但这不起作用。

用vscode运行显示,与配置不匹配的文件仍在检查中

[69] Check workspace: /home/pig208/myproject
[69] Using config file: pyproject.toml
[69] Received python path from Python extension: /home/pig208/myproject/.venv/bin/python
[69] Running dmypy in folder /home/pig208/myproject
/home/pig208/myproject/.venv/bin/python -m mypy.dmypy --status-file /home/pig208/.vscode-server/data/User/workspaceStorage/640660fb9d95e4f81c730061907f1d4c/matangover.mypy/dmypy-d1f12cdee9d0591a310a9c4402749ab59684e6e7.json run --log-file /home/pig208/.vscode-server/data/User/workspaceStorage/640660fb9d95e4f81c730061907f1d4c/matangover.mypy/dmypy-d1f12cdee9d0591a310a9c4402749ab59684e6e7.log -- . --show-column-numbers --no-error-summary --no-pretty --no-color-output --config-file pyproject.toml --python-executable /home/pig208/myproject/.venv/bin/python
[69] Mypy output:
analytics/foo.py:12:1: error: Need type annotation for "test_foo" (hint: "test_foo: Dict[<type>, <type>] = ...")

当我在命令行中运行 mypy 时,files 配置似乎仍然被忽略:

$ mypy . --config pyproject.toml
analytics/foo.py:12: error: Need type annotation for "test_foo" (hint: "test_foo: Dict[<type>, <type>] = ...")
Found 1 error in 1 file (checked 15 source files)

(exclude 可以解决问题,但我仍然想让files 工作)

【问题讨论】:

    标签: python visual-studio-code mypy


    【解决方案1】:

    这是因为您正在检查的脚本依赖于analytics/foo.py。因此,检查确定server/**/*_some_files.py中的类型。

    【讨论】:

      猜你喜欢
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      相关资源
      最近更新 更多