Skip to content

Commit af38823

Browse files
authored
Narrow down annotations for fields.Field.formfield (#1739)
Fixes: #1738
1 parent 0e72050 commit af38823

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

django-stubs/db/models/fields/__init__.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from datetime import date, time, timedelta
55
from datetime import datetime as real_datetime
66
from typing import Any, ClassVar, Generic, Literal, Protocol, TypeVar, overload
77

8+
from django import forms
89
from django.core import validators # due to weird mypy.stubtest error
910
from django.core.checks import CheckMessage
1011
from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
@@ -202,7 +203,12 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
202203
def get_db_prep_save(self, value: Any, connection: BaseDatabaseWrapper) -> Any: ...
203204
def get_internal_type(self) -> str: ...
204205
# TODO: plugin support
205-
def formfield(self, form_class: Any | None = ..., choices_form_class: Any | None = ..., **kwargs: Any) -> Any: ...
206+
def formfield(
207+
self,
208+
form_class: type[forms.Field] | None = ...,
209+
choices_form_class: Any | None = ...,
210+
**kwargs: Any,
211+
) -> Field: ...
206212
def save_form_data(self, instance: Model, data: Any) -> None: ...
207213
def contribute_to_class(self, cls: type[Model], name: str, private_only: bool = ...) -> None: ...
208214
def to_python(self, value: Any) -> Any: ...

0 commit comments

Comments
 (0)