Skip to content

Incorrect bound type for BaseDeleteView.form_class, should be plain Form. #2777

@sjoerdjob

Description

@sjoerdjob

Bug report

The type-stubs for BaseDeleteView and DeleteView incorrectly require the form value to be a ModelForm, while Django documentation implies a plain Form should be enough.

What's wrong

The Django stubs for django.views.generic.edit state the following:

class BaseDeleteView(Generic[_M, _ModelFormT], DeletionMixin[_M], FormMixin[_ModelFormT], BaseDetailView[_M]):
class DeleteView(Generic[_M, _ModelFormT], SingleObjectTemplateResponseMixin, BaseDeleteView[_M, _ModelFormT]):

looking at the actual implementation however,

class BaseDeleteView(DeletionMixin, FormMixin, BaseDetailView):
    ...
    form_class = Form

The Django documentation itself also states that the default form is the empty form: https://docs.djangoproject.com/en/5.2/ref/class-based-views/generic-editing/#django.views.generic.edit.DeleteView.form_class, suggesting that using a non-model-form is indeed acceptable behavior.

How is that should be

I think the stubs should read

class BaseDeleteView(Generic[_M, _FormT], DeletionMixin[_M], FormMixin[_FormT], BaseDetailView[_M]):
class DeleteView(Generic[_M, _FormT], SingleObjectTemplateResponseMixin, BaseDeleteView[_M, _FormT]):

System information

(I think all of the following are irrelevant, but just in case):

  • OS: Debian Linux.
  • python version: Python 3.13.6
  • django version: 5.2.5
  • mypy version: 1.17.1
  • django-stubs version: 5.2.2
  • django-stubs-ext version: 5.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions