Python Marshmallow type stubs for mypy

Viewed 343

I have tried to find type stubs for the popular Marshmallow [de]serialization library commonly used with Flask. I see how, given the often dynamic nature of the library's functionality, typing it might be difficult, but it would still be interesting to know if any meaningful work has been put into it.

TLDR: Are there type stubs for Marshmallow?

1 Answers

Marshmallow distributes type information as part of the package. There are no separate stubs because there is no need for them.

If you want to learn about the mechanism it uses, look at PEP561. It includes a py.typed file via its setup.py which indicates that the package provides type annotations.

If you're unsure how to use this with mypy, simply install marshmallow in the same environment as mypy. e.g. If using virtualenvs, install mypy and marshmallow in the same virtualenv, just as you would install a type stub package.

Related