我正在为我正在处理的一个项目准备一些预提交钩子,其中一个钩子是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)
关于这里可能出错的建议将不胜感激,谢谢!