summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-09-04 12:56:50 +0100
committerGitHub <noreply@github.com>2023-09-04 13:56:50 +0200
commit8c8cbe66fa4354a3c50e4f5f248fcf5fd597e724 (patch)
tree3e1fc24252ed761419e68e0c38dbdd75cdb6b5c0
parenta534835c7b4cf1556638edd39acde7b2b88c8892 (diff)
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.
-rw-r--r--django/forms/models.py4
-rw-r--r--django/utils/choices.py6
2 files changed, 5 insertions, 5 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index d353da4ddc..ff4b83fe59 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -21,7 +21,7 @@ from django.forms.widgets import (
RadioSelect,
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.translation import gettext
from django.utils.translation import gettext_lazy as _
@@ -1403,7 +1403,7 @@ class ModelChoiceIteratorValue:
return self.value == other
-class ModelChoiceIterator(ChoiceIterator):
+class ModelChoiceIterator(BaseChoiceIterator):
def __init__(self, field):
self.field = field
self.queryset = field.queryset
diff --git a/django/utils/choices.py b/django/utils/choices.py
index ccedf828a0..93a34e403d 100644
--- a/django/utils/choices.py
+++ b/django/utils/choices.py
@@ -3,11 +3,11 @@ from collections.abc import Callable, Iterable, Iterator, Mapping
from django.utils.functional import Promise
-class ChoiceIterator:
+class BaseChoiceIterator:
"""Base class for lazy iterators for choices."""
-class CallableChoiceIterator(ChoiceIterator):
+class CallableChoiceIterator(BaseChoiceIterator):
"""Iterator to lazily normalize choices generated by a callable."""
def __init__(self, func):
@@ -23,7 +23,7 @@ def normalize_choices(value, *, depth=0):
from django.db.models.enums import ChoicesMeta
match value:
- case ChoiceIterator() | Promise() | bytes() | str():
+ case BaseChoiceIterator() | Promise() | bytes() | str():
# Avoid prematurely normalizing iterators that should be lazy.
# Because string-like types are iterable, return early to avoid
# iterating over them in the guard for the Iterable case below.