Configuring the Pydantic Mypy Plugin in pyproject.toml

Wherein I configure mypy using pyproject.toml

I usually use pyproject.toml to configure my Python projects.

I also use mypy to do some type checking.

In a project using Pydantic you need to enable the Pydantic Mypy plugin or else you're likely to see a whole bunch of spurious type errors.

If you want to enable the plugin using pyproject.toml add the following to your pyproject.toml file:

plugins = "pydantic.mypy"

The mypy pyproject.toml configuration docs covers how to map configuration options to pyproject.toml.

Bonus: More Than One Plugin

If you need to enable multiple plugins use the following:

plugins = ["pydantic.mypy", "sqlalchemy.ext.mypy.plugin"]