为什么从打字中看到类型的Mypy?

发布于 2025-02-03 12:24:58 字数 759 浏览 3 评论 0原文

我正在尝试将更多的MyPy类型注释添加到我现有的代码库中。我有一个使用大量BS4的文件。

当我在此文件上运行mypy检查器时,我会遇到错误:

error: Skipping analyzing "bs4": module is installed, but missing library stubs or py.typed marker

mypy文档“缺少库存根” 它说:

mypy不会尝试推断您安装的任何第三方库的类型/strong>,标准库和某些第三方库的类型存储库。

但是当i 看打字 >一组存根。如何解决该错误并告诉它查看Typeshed的存根定义?

BS4和Mypy都在运行最新版本。

<在我的代码中,Mypy并没有抱怨,但似乎他们以不同的方式解决了它,因为打字中没有黑色存根。

I'm trying to add more mypy type annotations to my existing codebase. I have a file that uses a lot of bs4.

When I run the mypy checker on this file I get the error:

error: Skipping analyzing "bs4": module is installed, but missing library stubs or py.typed marker

In the mypy docs on "Missing library stubs" it says:

Mypy will not try inferring the types of any 3rd party libraries you have installed unless they either have declared themselves to be PEP 561 compliant stub package (e.g. with a py.typed file) or have registered themselves on typeshed, the repository of types for the standard library and some 3rd party libraries.

But when I look on typeshed, there is a set of stubs. How do I fix that error and tell it to look at the stub definition from typeshed?

BS4 and mypy are both running the latest version.

This question asks a similar question about black, but when I test black in my code mypy doesn't complain but it seems that they've solved it in a different way as there's no black stub in typeshed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2025-02-10 12:24:59

这是 mypy打字 。它不包括第三方库,仅限于标准库。因此,BeautifulSoup的类型未使用mypy发货(这样做真的很奇怪,因为这些存根有时比mypy 本身,加上其他TypeCheckers依赖于此打字)。因此,您需要单独安装所需的存根( package home page ):

pip install types-beautifulsoup4

Here is the content of mypy typeshed. It doesn't include third-party libraries, limited only to standard library. So types for beautifulsoup are not shipped with mypy (and it would be really odd to do so, because these stubs are updated sometimes more often than mypy itself, plus other typecheckers rely on this typeshed). So you need to install required stubs separately (package home page):

pip install types-beautifulsoup4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文