Ben
Ben

Reputation: 13332

Why isn't mypy seeing types from typeshed?

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.

Upvotes: 5

Views: 4256

Answers (1)

STerliakov
STerliakov

Reputation: 7858

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

Upvotes: 1

Related Questions