Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for mypy plugins to enable django-stubs testing #13935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huynguyengl99 opened this issue May 4, 2025 · 0 comments · Fixed by #13948
Closed

Add support for mypy plugins to enable django-stubs testing #13935

huynguyengl99 opened this issue May 4, 2025 · 0 comments · Fixed by #13948
Labels
project: infrastructure typeshed build, test, documentation, or distribution related

Comments

@huynguyengl99
Copy link
Contributor

We can support Django type checking via mypy's django-stubs plugin. The required mypy.ini configuration is simply:

[mypy]
plugins = mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = scripts.tests_settings

With a minimal tests_settings.py file:

SECRET_KEY = "1"
INSTALLED_APPS = (
    "django.contrib.contenttypes",
    "django.contrib.sites",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.admin.apps.SimpleAdminConfig",
    "django.contrib.staticfiles",
    "django.contrib.auth",
    "channels",
)

I propose we extend our typing tools to support mypy plugins by adding the "plugins" field to the KNOWN_METADATA_TOOL_FIELDS dictionary:

KNOWN_METADATA_TOOL_FIELDS: Final = {
    "stubtest": {
        "skip",
        "apt_dependencies",
        "brew_dependencies",
        "choco_dependencies",
        "extras",
        "ignore_missing_stub",
        "platforms",
        "stubtest_requirements",
    },
    "mypy": {
        "plugins",
    }
}

This would allow package maintainers to specify in their METADATA.toml:

[tool.mypy]
plugins = "mypy_django_plugin.main"

[tool.mypy.plugins.django-stubs]
django_settings_module = "scripts.tests_settings"

This enhancement would enable proper stubtest functionality for Django-based stubs libraries. What do you think about this idea?

@AlexWaygood AlexWaygood added the project: infrastructure typeshed build, test, documentation, or distribution related label May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: infrastructure typeshed build, test, documentation, or distribution related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants