Skip to content

Types for django.db.models.fields.formfield #1738

@WhyNotHugo

Description

@WhyNotHugo

Bug report

For the type django.db.models.fields.formfield.Field, the function formfield currently has the following type.

def formfield(self, form_class: Any | None = ..., choices_form_class: Any | None = ..., **kwargs: Any) -> Any: ...

What's wrong

The form_class attribute is type[forms.Field], and the return value is forms.Field:

def formfield(self, form_class: type[forms.Field] | None = ..., choices_form_class: Any | None = ..., **kwargs: Any) -> forms.Field: ...

How is that should be

This isn't specific enough: the return value is of the same type of form_class, so there is a relationship between the two.

However, I'm not sure how to represent this type relationship. Should I use a Protocol for the entire type?

System information

Current master of this project. All else is out of scope here.

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