预提交 MyPy 无法禁用非错误消息

问题描述 投票:0回答:1

我正在为我正在开发的项目组合一些预提交挂钩,我们想要使用的挂钩之一是 MyPy。预提交结果抛出了许多与“注释未选中”标志相关的非错误注释,我想禁用它以消除命令行输出的混乱。

我从上一个问题Suppress Mypy Notes中看到,解决方案是在

disable_error_code = ["annotation-unchecked"]
文件中包含
pyproject.toml
,但是,在运行预提交时,注释仍然会出现。

这些是

pyproject.toml
文件中对 MyPy 的当前引用:

[tool.mypy]
mypy_path = "src"
disable_error_code = ["annotation-unchecked"]  # Disables non-error messages thrown up by mypy

这些是

pre-commit-config.yaml
文件中的设置:

# Type checking
- repo: https://github.com/pre-commit/mirrors-mypy
  #rev: v0.910
  rev: v1.9.0
  hooks:
  - id: mypy
    files: '(src|tests)/.*\.py$'  # Single quote critical due to escape character '\' used in RegEx search string (see YAML - 7.3 Flow Scalar Styles)
    additional_dependencies: [types-requests]

这些是在命令行中打印出的 MyPy 消息。请注意,尽管进行了上述设置,“注释”仍然被打印。

src/pkg/file1.py:14: error: Argument 2 to "from_bytes" of "int" has incompatible type "str"; expected "Literal['little', 'big']"  [arg-type]
src/pkg/file1.py:21: error: Argument 2 to "from_bytes" of "int" has incompatible type "str"; expected "Literal['little', 'big']"  [arg-type]
src/pkg/file1.py:23: error: Argument 2 to "from_bytes" of "int" has incompatible type "str"; expected "Literal['little', 'big']"  [arg-type]
src/pkg/file2.py:60: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file3.py:143: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file4.py:125: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file4.py:126: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file5.py:20: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file5.py:21: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file6.py:75: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file7.py:164: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/pkg/file8.py:709: error: Value of type "Coroutine[Any, Any, None]" must be used  [unused-coroutine]
src/pkg/file9.py:709: note: Are you missing an await?
src/pkg/file10.py:267: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 4 errors in 2 files (checked 72 source files)

非常感谢有关此处可能出现问题的建议,谢谢!

python mypy pre-commit-hook
1个回答
0
投票

您必须通过 mypy 的参数将 .pyproject.toml 作为配置传递,例如

- repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.9.0
    hooks:
      - id: mypy
        files: '(src|tests)/.*\.py$'  # Single quote critical due to escape character '\' used in RegEx search string (see YAML - 7.3 Flow Scalar Styles)
        additional_dependencies: [types-requests]
        args: [--config-file=./pyproject.toml]
© www.soinside.com 2019 - 2024. All rights reserved.