@@ -11,6 +11,8 @@ from django.utils.translation import ugettext_lazy as _
1111from django .utils .functional import cached_property
1212from typing_extensions import Literal
1313
14+ from django_stubs_ext import StrOrPromise
15+
1416from rest_framework .exceptions import APIException as APIException
1517from rest_framework .exceptions import AuthenticationFailed as AuthenticationFailed
1618from rest_framework .exceptions import ErrorDetail as ErrorDetail
@@ -97,10 +99,10 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]):
9799 default : Any = ...,
98100 initial : Any = ...,
99101 source : str = ...,
100- label : str = ...,
101- help_text : str = ...,
102+ label : StrOrPromise = ...,
103+ help_text : StrOrPromise = ...,
102104 style : dict [str , Any ] = ...,
103- error_messages : dict [str , str ] = ...,
105+ error_messages : dict [str , StrOrPromise ] = ...,
104106 validators : Sequence [Validator [Any ]] | None = ...,
105107 allow_null : bool = ...,
106108 ): ...
@@ -132,7 +134,7 @@ class Serializer(
132134 metaclass = SerializerMetaclass ,
133135):
134136 _declared_fields : dict [str , Field ]
135- default_error_messages : dict [str , Any ]
137+ default_error_messages : dict [str , StrOrPromise ]
136138 def get_initial (self ) -> Any : ...
137139 @cached_property
138140 def fields (self ) -> BindingDict : ...
@@ -155,7 +157,7 @@ class ListSerializer(
155157):
156158 child : Field | BaseSerializer | None
157159 many : bool
158- default_error_messages : dict [str , Any ]
160+ default_error_messages : dict [str , StrOrPromise ]
159161 allow_empty : bool | None
160162 def __init__ (
161163 self ,
@@ -171,10 +173,10 @@ class ListSerializer(
171173 default : Any = ...,
172174 initial : Any = ...,
173175 source : str = ...,
174- label : str = ...,
175- help_text : str = ...,
176+ label : StrOrPromise = ...,
177+ help_text : StrOrPromise = ...,
176178 style : dict [str , Any ] = ...,
177- error_messages : dict [str , str ] = ...,
179+ error_messages : dict [str , StrOrPromise ] = ...,
178180 validators : Sequence [Validator [list [Any ]]] | None = ...,
179181 allow_null : bool = ...,
180182 ): ...
@@ -216,10 +218,10 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]):
216218 default : _MT | Sequence [_MT ] | Callable [[], _MT | Sequence [_MT ]] = ...,
217219 initial : _MT | Sequence [_MT ] | Callable [[], _MT | Sequence [_MT ]] = ...,
218220 source : str = ...,
219- label : str = ...,
220- help_text : str = ...,
221+ label : StrOrPromise = ...,
222+ help_text : StrOrPromise = ...,
221223 style : dict [str , Any ] = ...,
222- error_messages : dict [str , str ] = ...,
224+ error_messages : dict [str , StrOrPromise ] = ...,
223225 validators : Sequence [Validator [_MT ]] | None = ...,
224226 allow_null : bool = ...,
225227 allow_empty : bool = ...,
0 commit comments