简体   繁体   English

强制 mypy 对第三方 package 进行类型检查

[英]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.

相关问题 如何在Python Canopy中安装第三方软件包? - How can I install a Third-Party Package in Python Canopy? 如何覆盖第三方 django 包的迁移 - How to override the migrations of a third-party django package 是否轻松将所有第三方软件包和脚本作为通用软件包导入? - Easily importing all third-party packages and scripts as a common package? 什么是“第三方模块”? - What are “third-party modules”? 如果我需要编辑第三方包的`setup.py`,我应该如何在我的包中使用第三方包? - How should I use a third-party package in my package if I need to edit the third-party package's `setup.py`? 如何使用 Celery(无第三方包)发送 Django 的密码重置邮件? - How to send Django's password reset email using Celery (without third-party package)? Python:如何安装第三方程序包并使其他团队可以使用 - Python: How to install a third-party package and make it available to rest of team 我的单元测试是否也应该测试第三方库/包功能? - Should my unit tests also test third-party library/package features? 第三方 SDK 和线程安全 - Third-party SDKs and thread-safety 使用第三方库进行Python部署 - Python deployment with third-party libraries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM