[英]Force mypy to typecheck third-party package
I'm using a third-party package (in this case jsonrpcserver though this problem could apply to other packages) that is fully type-aware, and even includes a py.typed
file in its sources.我正在使用完全类型感知的第三方 package(在本例中为 jsonrpcserver ,尽管此问题可能适用于其他包),甚至在其源代码中包含一个py.typed
文件。
However, due to a packaging bug, the py.typed
file is not installed.但是,由于打包错误,未安装py.typed
文件。
As a result, mypy insists结果,mypy 坚持
error: Skipping analyzing 'jsonrpcserver.response': found module but no type hints or library stubs
Even though I can say for a fact that the module does have type hints.尽管我可以说模块确实有类型提示。 Is there a way I can force mypy to analyze this package even if it's missing the py.typed
?有没有办法可以强制mypy 分析这个 package 即使它缺少py.typed
? I shouldn't have to create a stub library for this purpose since the package is otherwise type-aware.我不应该为此目的创建一个存根库,因为 package 是其他类型的感知器。
I don't know of a nice way to do that.我不知道这样做的好方法。 There is some discussion in this mypy github issue about introducing a flag for exactly this purpose, but it's not there yet.在这个 mypy github 问题中有一些关于为此目的引入标志的讨论,但还没有。
A less nice way for now could be creating the py.typed
file yourself before running mypy (mentioned here ).现在一个不太好的方法可能是在运行 mypy 之前自己创建py.typed
文件(在此处提到)。 Perhaps as part of a script that sets up the test environment or similar.也许作为设置测试环境或类似的脚本的一部分。
Getting the right path for that file:获取该文件的正确路径:
python -c 'import jsonrpcserver; print(jsonrpcserver.__path__[0] + "/py.typed")'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.