mirror of
https://github.com/django/django.git
synced 2025-08-30 21:59:32 +00:00
Refs #31262 -- Renamed ChoiceIterator to BaseChoiceIterator.
Some third-party applications, e.g. `django-filter`, already define their own `ChoiceIterator`, so renaming this `BaseChoiceIterator` will be a better fit and avoid any potential confusion. See https://github.com/carltongibson/django-filter/pull/1607.
This commit is contained in:
parent
a534835c7b
commit
8c8cbe66fa
@ -21,7 +21,7 @@ from django.forms.widgets import (
|
|||||||
RadioSelect,
|
RadioSelect,
|
||||||
SelectMultiple,
|
SelectMultiple,
|
||||||
)
|
)
|
||||||
from django.utils.choices import ChoiceIterator
|
from django.utils.choices import BaseChoiceIterator
|
||||||
from django.utils.text import capfirst, get_text_list
|
from django.utils.text import capfirst, get_text_list
|
||||||
from django.utils.translation import gettext
|
from django.utils.translation import gettext
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -1403,7 +1403,7 @@ class ModelChoiceIteratorValue:
|
|||||||
return self.value == other
|
return self.value == other
|
||||||
|
|
||||||
|
|
||||||
class ModelChoiceIterator(ChoiceIterator):
|
class ModelChoiceIterator(BaseChoiceIterator):
|
||||||
def __init__(self, field):
|
def __init__(self, field):
|
||||||
self.field = field
|
self.field = field
|
||||||
self.queryset = field.queryset
|
self.queryset = field.queryset
|
||||||
|
@ -3,11 +3,11 @@ from collections.abc import Callable, Iterable, Iterator, Mapping
|
|||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
|
|
||||||
|
|
||||||
class ChoiceIterator:
|
class BaseChoiceIterator:
|
||||||
"""Base class for lazy iterators for choices."""
|
"""Base class for lazy iterators for choices."""
|
||||||
|
|
||||||
|
|
||||||
class CallableChoiceIterator(ChoiceIterator):
|
class CallableChoiceIterator(BaseChoiceIterator):
|
||||||
"""Iterator to lazily normalize choices generated by a callable."""
|
"""Iterator to lazily normalize choices generated by a callable."""
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
@ -23,7 +23,7 @@ def normalize_choices(value, *, depth=0):
|
|||||||
from django.db.models.enums import ChoicesMeta
|
from django.db.models.enums import ChoicesMeta
|
||||||
|
|
||||||
match value:
|
match value:
|
||||||
case ChoiceIterator() | Promise() | bytes() | str():
|
case BaseChoiceIterator() | Promise() | bytes() | str():
|
||||||
# Avoid prematurely normalizing iterators that should be lazy.
|
# Avoid prematurely normalizing iterators that should be lazy.
|
||||||
# Because string-like types are iterable, return early to avoid
|
# Because string-like types are iterable, return early to avoid
|
||||||
# iterating over them in the guard for the Iterable case below.
|
# iterating over them in the guard for the Iterable case below.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user