首页 > 解决方案 > mypy - 如何处理签入存储库的第三方代码

问题描述

MCVE 将是:

$ mkdir ext_libs
$ pip install Twisted==19.7.0 -t ext_libs
$ ls
client.py  ext_libs  mypy.ini 

客户端.py:

import twisted
print(twisted.__version__)

mypy.ini:

[mypy]
mypy_path=ext_libs:.
exclude=ext_libs/
follow_imports=normal

运行命令:mypy client.py 输出:

$ mypy client.py
ext_libs\incremental\__init__.py:25: error: Name "cmp" is not defined
ext_libs\incremental\__init__.py:125: error: Cannot assign to a type
ext_libs\incremental\__init__.py:125: error: Incompatible types in assignment (expression has type "_inf", variable has type "Type[_inf]")
Found 3 errors in 1 file (checked 1 source file)

我如何强制 mypy 排除对 ext_libs 内容的错误检查(将这些文件视为任何其他站点包)?

标签: pythonpython-3.xstatic-analysismypy

解决方案


推荐阅读