Force mypy to typecheck third-party package

Viewed 309

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.

However, due to a packaging bug, the py.typed file is not installed.

As a result, mypy insists

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? I shouldn't have to create a stub library for this purpose since the package is otherwise type-aware.

1 Answers

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.

A less nice way for now could be creating the py.typed file yourself before running mypy (mentioned here). 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")'
Related