diff --git a/django_stubs_ext/django_stubs_ext/patch.py b/django_stubs_ext/django_stubs_ext/patch.py index 5c6ba1e..1796b76 100644 --- a/django_stubs_ext/django_stubs_ext/patch.py +++ b/django_stubs_ext/django_stubs_ext/patch.py @@ -6,6 +6,7 @@ from django.contrib.admin.options import BaseModelAdmin from django.db.models.fields import Field from django.db.models.manager import BaseManager from django.db.models.query import QuerySet +from django.forms.models import BaseModelForm from django.views.generic.detail import SingleObjectMixin from django.views.generic.edit import FormMixin from django.views.generic.list import MultipleObjectMixin @@ -44,6 +45,7 @@ _need_generic: List[MPGeneric[Any]] = [ MPGeneric(MultipleObjectMixin), MPGeneric(BaseModelAdmin), MPGeneric(Field), + MPGeneric(BaseModelForm), # These types do have native `__class_getitem__` method since django 3.1: MPGeneric(QuerySet, (3, 1)), MPGeneric(BaseManager, (3, 1)), diff --git a/django_stubs_ext/tests/test_monkeypatching.py b/django_stubs_ext/tests/test_monkeypatching.py index 09d844d..4e3c162 100644 --- a/django_stubs_ext/tests/test_monkeypatching.py +++ b/django_stubs_ext/tests/test_monkeypatching.py @@ -5,6 +5,8 @@ from typing import Optional import pytest from _pytest.fixtures import FixtureRequest from _pytest.monkeypatch import MonkeyPatch +from django.db.models import Model +from django.forms.models import ModelForm from typing_extensions import Protocol import django_stubs_ext @@ -46,6 +48,9 @@ def test_patched_generics(make_generic_classes: _MakeGenericClasses) -> None: if el.version is None: assert el.cls[type] is el.cls # `type` is arbitrary + class TestForm(ModelForm[Model]): + pass + @pytest.mark.parametrize( "django_version",