我正在使用Mypy v0.910
运行pre-commit
。它抱怨python-dateutil
没有类型存根。但是,即使在安装存根之后,我也会得到相同的错误。
我的预提交配置是
default_language_version:
python: python3
repos:
<other hooks>
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
args:
- --install-types
additional_dependencies: [tokenize-rt==3.2.0]
当我尝试提交时,它会抱怨存根不存在,然后无法安装它们。
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
coordinator/policy.py:5: error: Library stubs not installed for "dateutil.parser" (or incompatible with Python 3.7)
coordinator/policy.py:5: note: Hint: "python3 -m pip install types-python-dateutil"
coordinator/policy.py:5: note: (or run "mypy --install-types" to install all missing stub packages)
tests/test_policy.py:6: error: Cannot find implementation or library stub for module named "pyhocon"
coordinator/configuration.py:4: error: Cannot find implementation or library stub for module named "pyhocon"
coordinator/configuration.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 3 errors in 3 files (checked 7 source files)
Installing missing stub packages:
/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/bin/python -m pip install types-python-dateutil
Install? [yN] Traceback (most recent call last):
File "/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/lib/python3.7/site-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 120, in main
File "mypy/main.py", line 1161, in install_types
EOFError: EOF when reading a line
在python:https://github.com/dateutil/dateutil/issues/383上似乎存在一个与此相关的未决问题。
有没有办法告诉Mypy
不要担心丢失的存根?目前,我能想到的唯一解决办法就是完全禁用Mypy
。
发布于 2022-08-16 14:06:29
这个问题仍然存在于最新的mypy 0.971上。
这就是引起问题的钩子。
- hooks:
- description: Type checking for Python
exclude: tests/.*$
id: mypy
repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
我唯一能解决的方法是修改上面的钩子
- hooks:
- additional_dependencies: [types-python-dateutil==2.8.19]
description: Type checking for Python
exclude: tests/.*$
id: mypy
repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
当以诗歌的形式在本地运行mypy src时,仍然需要将types python-dateutil添加为dev依赖项。
发布于 2022-07-21 10:56:49
根据下面的链接,mypy的0.931版似乎没有发生这种情况:https://github.com/python/mypy/issues/11920
https://stackoverflow.com/questions/69638952
复制相似问题