我正在为我正在处理的一个项目准备一些预提交钩子,其中一个钩子是MyPy.预提交结果会抛出许多与"annotation—unchecked"标志相关的非错误注释,我想禁用该标志以消除命令行输出的混乱.

我从前面的问题Suppress Mypy notes中看到,解决方案是在pyproject.toml文件中包含一个disable_error_code = ["annotation-unchecked"],然而,在运行预提交时仍然会出现注释.

以下是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)

关于这里可能出错的建议将不胜感激,谢谢!

推荐答案

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

- 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]

Python相关问答推荐

如何才能知道Python中2列表中的巧合.顺序很重要,但当1个失败时,其余的不应该失败或是0巧合

点到面的Y距离

根据另一列中的nan重置值后重新加权Pandas列

try 在树叶 map 上应用覆盖磁贴

发生异常:TclMessage命令名称无效.!listbox"

如何获取numpy数组的特定索引值?

如何使用表达式将字符串解压缩到Polars DataFrame中的多个列中?

将tdqm与cx.Oracle查询集成

如果条件不满足,我如何获得掩码的第一个索引并获得None?

如何在Polars中从列表中的所有 struct 中 Select 字段?

将scipy. sparse矩阵直接保存为常规txt文件

PYTHON、VLC、RTSP.屏幕截图不起作用

pandas:在操作pandora之后将pandora列转换为int

Python如何导入类的实例

Seaborn散点图使用多个不同的标记而不是点

利用SCIPY沿第一轴对数组进行内插

Pandas:将值从一列移动到适当的列

如何在Python中解析特定的文本,这些文本包含了同一行中的所有内容,

查找数据帧的给定列中是否存在特定值

了解如何让库认识到我具有所需的依赖项