Django Stubs Extensions
django-stubs-ext is a Python library that provides essential monkey-patching and extensions for `django-stubs`, significantly enhancing static type checking for Django projects using Mypy. It ensures better compatibility and stub coverage for advanced Django features and commonly used patterns. The library is actively maintained with frequent updates, often aligning with new Django and Mypy releases, and is currently at version 6.0.2.
Warnings
- breaking Version 6.0.0 introduced significant changes, including dropping support for older Django versions and primarily targeting Django 6.0. Ensure your Django project is compatible.
- breaking `django-stubs-ext` versions 6.0.x are designed for `mypy@1.20` and newer. Using older Mypy versions might lead to compatibility issues or incorrect type checking results.
- gotcha Version 6.0.0 of `django-stubs-ext` contained a known crash bug when checking `QuerySet.order_by()` with abstract models. This issue was resolved in subsequent patch releases.
- gotcha For `django-stubs-ext` to function correctly, it must be used in conjunction with `django-stubs`. Ensure both libraries are installed and your Mypy configuration points to the `django_stubs_ext.mypy_plugin`.
Install
-
pip install django-stubs-ext
Imports
- django_stubs_ext.mypy_plugin
Add 'django_stubs_ext.mypy_plugin' to `mypy_plugins` in `mypy.ini`.
Quickstart
[mypy] plugins = django_stubs_ext.mypy_plugin