Add mypy plugin support to stubtest configuration (#13948)

This commit is contained in:
Huy Nguyen
2025-05-11 19:45:30 +07:00
committed by GitHub
parent 0933303ff0
commit a8fa1ab0d9
6 changed files with 61 additions and 5 deletions
+17
View File
@@ -196,6 +196,23 @@ that stubtest reports to be missing should necessarily be added to the stub.
For some implementation details, it is often better to add allowlist entries
for missing objects rather than trying to match the runtime in every detail.
### Support for mypy plugins in stubtest
For stubs that require mypy plugins to check correctly (such as Django), stubtest
supports configuring mypy plugins through the METADATA.toml file. This allows stubtest to
leverage type information provided by these plugins when validating stubs.
To use this feature, add the following configuration to the `tool.stubtest` section in your METADATA.toml:
```toml
mypy_plugins = ["mypy_django_plugin.main"]
mypy_plugins_config = { "django-stubs" = { "django_settings_module" = "@tests.django_settings" } }
```
For Django stubs specifically, you'll need to create a `django_settings.py` file in your `@tests` directory
that contains the Django settings required by the plugin. This file will be referenced by the plugin
configuration to properly validate Django-specific types during stubtest execution.
## typecheck\_typeshed.py
Run using