@@ -15,6 +15,7 @@ from django.db.models.expressions import Col, Combinable, Expression
1515from django .db .models .fields .reverse_related import ForeignObjectRel
1616from django .db .models .query_utils import Q , RegisterLookupMixin
1717from django .forms import Widget
18+ from django .utils .choices import BlankChoiceIterator , _Choice , _ChoiceNamedGroup , _Choices , _ChoicesCallable
1819from django .utils .datastructures import DictWrapper
1920from django .utils .functional import _Getter , _StrOrPromise , cached_property
2021from typing_extensions import Self , TypeAlias
@@ -24,19 +25,11 @@ class NOT_PROVIDED: ...
2425
2526BLANK_CHOICE_DASH : list [tuple [str , str ]]
2627
27- _Choice : TypeAlias = tuple [Any , Any ]
28-
29- _ChoiceNamedGroup : TypeAlias = tuple [str , Iterable [_Choice ]]
30- _FieldChoices : TypeAlias = Iterable [_Choice | _ChoiceNamedGroup ]
3128_ChoicesList : TypeAlias = Sequence [_Choice ] | Sequence [_ChoiceNamedGroup ]
3229_LimitChoicesTo : TypeAlias = Q | dict [str , Any ]
3330
3431_F = TypeVar ("_F" , bound = Field , covariant = True )
3532
36- @type_check_only
37- class _ChoicesCallable (Protocol ):
38- def __call__ (self ) -> _FieldChoices : ...
39-
4033@type_check_only
4134class _FieldDescriptor (Protocol [_F ]):
4235 """
@@ -175,7 +168,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
175168 unique_for_date : str | None = ...,
176169 unique_for_month : str | None = ...,
177170 unique_for_year : str | None = ...,
178- choices : _FieldChoices | None = ...,
171+ choices : _Choices | None = ...,
179172 help_text : _StrOrPromise = ...,
180173 db_column : str | None = ...,
181174 db_tablespace : str | None = ...,
@@ -227,7 +220,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
227220 blank_choice : _ChoicesList = ...,
228221 limit_choices_to : _LimitChoicesTo | None = ...,
229222 ordering : Sequence [str ] = ...,
230- ) -> _ChoicesList : ...
223+ ) -> BlankChoiceIterator | _ChoicesList : ...
231224 def _get_flatchoices (self ) -> list [_Choice ]: ...
232225 @property
233226 def flatchoices (self ) -> list [_Choice ]: ...
@@ -288,7 +281,7 @@ class DecimalField(Field[_ST, _GT]):
288281 editable : bool = ...,
289282 auto_created : bool = ...,
290283 serialize : bool = ...,
291- choices : _FieldChoices | None = ...,
284+ choices : _Choices | None = ...,
292285 help_text : _StrOrPromise = ...,
293286 db_column : str | None = ...,
294287 db_comment : str | None = ...,
@@ -320,7 +313,7 @@ class CharField(Field[_ST, _GT]):
320313 unique_for_date : str | None = ...,
321314 unique_for_month : str | None = ...,
322315 unique_for_year : str | None = ...,
323- choices : _FieldChoices | None = ...,
316+ choices : _Choices | None = ...,
324317 help_text : _StrOrPromise = ...,
325318 db_column : str | None = ...,
326319 db_comment : str | None = ...,
@@ -350,7 +343,7 @@ class SlugField(CharField[_ST, _GT]):
350343 unique_for_date : str | None = ...,
351344 unique_for_month : str | None = ...,
352345 unique_for_year : str | None = ...,
353- choices : _FieldChoices | None = ...,
346+ choices : _Choices | None = ...,
354347 help_text : _StrOrPromise = ...,
355348 db_column : str | None = ...,
356349 db_comment : str | None = ...,
@@ -385,7 +378,7 @@ class URLField(CharField[_ST, _GT]):
385378 unique_for_date : str | None = ...,
386379 unique_for_month : str | None = ...,
387380 unique_for_year : str | None = ...,
388- choices : _FieldChoices | None = ...,
381+ choices : _Choices | None = ...,
389382 help_text : _StrOrPromise = ...,
390383 db_column : str | None = ...,
391384 db_comment : str | None = ...,
@@ -418,7 +411,7 @@ class TextField(Field[_ST, _GT]):
418411 unique_for_date : str | None = ...,
419412 unique_for_month : str | None = ...,
420413 unique_for_year : str | None = ...,
421- choices : _FieldChoices | None = ...,
414+ choices : _Choices | None = ...,
422415 help_text : _StrOrPromise = ...,
423416 db_column : str | None = ...,
424417 db_comment : str | None = ...,
@@ -466,7 +459,7 @@ class GenericIPAddressField(Field[_ST, _GT]):
466459 editable : bool = ...,
467460 auto_created : bool = ...,
468461 serialize : bool = ...,
469- choices : _FieldChoices | None = ...,
462+ choices : _Choices | None = ...,
470463 help_text : _StrOrPromise = ...,
471464 db_column : str | None = ...,
472465 db_comment : str | None = ...,
@@ -501,7 +494,7 @@ class DateField(DateTimeCheckMixin, Field[_ST, _GT]):
501494 editable : bool = ...,
502495 auto_created : bool = ...,
503496 serialize : bool = ...,
504- choices : _FieldChoices | None = ...,
497+ choices : _Choices | None = ...,
505498 help_text : _StrOrPromise = ...,
506499 db_column : str | None = ...,
507500 db_comment : str | None = ...,
@@ -532,7 +525,7 @@ class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
532525 editable : bool = ...,
533526 auto_created : bool = ...,
534527 serialize : bool = ...,
535- choices : _FieldChoices | None = ...,
528+ choices : _Choices | None = ...,
536529 help_text : _StrOrPromise = ...,
537530 db_column : str | None = ...,
538531 db_comment : str | None = ...,
@@ -569,7 +562,7 @@ class UUIDField(Field[_ST, _GT]):
569562 unique_for_date : str | None = ...,
570563 unique_for_month : str | None = ...,
571564 unique_for_year : str | None = ...,
572- choices : _FieldChoices | None = ...,
565+ choices : _Choices | None = ...,
573566 help_text : _StrOrPromise = ...,
574567 db_column : str | None = ...,
575568 db_comment : str | None = ...,
@@ -606,7 +599,7 @@ class FilePathField(Field[_ST, _GT]):
606599 editable : bool = ...,
607600 auto_created : bool = ...,
608601 serialize : bool = ...,
609- choices : _FieldChoices | None = ...,
602+ choices : _Choices | None = ...,
610603 help_text : _StrOrPromise = ...,
611604 db_column : str | None = ...,
612605 db_comment : str | None = ...,
0 commit comments