Skip to content

Plugin configuration for the mypy plugin and docs#141

Merged
binaryDiv merged 6 commits intodev-mypyfrom
mypy-plugin-config
Apr 8, 2026
Merged

Plugin configuration for the mypy plugin and docs#141
binaryDiv merged 6 commits intodev-mypyfrom
mypy-plugin-config

Conversation

@binaryDiv
Copy link
Copy Markdown
Contributor

@binaryDiv binaryDiv commented Mar 12, 2026

IMPORTANT: This PR is marked as a draft because the branch is based on another branch: mypy-plugin.
It should be rebased on dev-mypy and only merged after that branch has been merged.


This is a part of making validataclass mypy-compatible (#116).
Please note that the target branch is dev-mypy instead of main.


This PR extends the mypy plugin introduced in #140 (not merged as of now) by a simple config system. It also adds some documentation on how to use the mypy plugin including the newly added settings.

The plugin config currently only supports the pyproject.toml format, which I think is fine because that's the recommended way to configure tooling for Python projects. The plugin automatically detects the config file used by mypy and reads the same file (if it ends on .toml).

The primary purpose of the plugin config is to support custom decorators and other extensions to validataclass, like those needed for the validataclass-search-queries library, or custom decorators that we have in some of our company's projects.

The PR introduces a conditional dependency to the library: For Python <3.11 (meaning 3.10), the library now requires the tomli library to parse TOML files. Since Python 3.11, the standard library contains tomllib which is fully API-compatible to tomli (I think it's literally the same library?). The tomli library itself is a simple library without any dependencies, so it stays lightweight.

@binaryDiv binaryDiv self-assigned this Mar 12, 2026
@binaryDiv binaryDiv added the new feature New feature that is not (only) a validator class label Mar 12, 2026
Base automatically changed from mypy-plugin to dev-mypy March 26, 2026 13:32
@binaryDiv binaryDiv marked this pull request as ready for review March 26, 2026 13:34
import tomli as tomllib


# TODO: Add unit tests for config parsing and error handling (and remove "pragma: nocover"s).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to solve this TODO in this MR or is that something for later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for later. Would love to do it now, but I've already been working way too long on this whole plugin. :/

And the config parsing is tested "good enough" for now, there's the mypy tests that make use of the config and I'm already using it in validataclass-search-queries. I'd just like to add some more unit tests later to fully cover it with unit tests.

@binaryDiv binaryDiv merged commit 3153154 into dev-mypy Apr 8, 2026
@binaryDiv binaryDiv deleted the mypy-plugin-config branch April 8, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature that is not (only) a validator class

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants