Skip to content

Commit

Permalink
Refs #31262 -- Renamed ChoiceIterator to BaseChoiceIterator.
Browse files Browse the repository at this point in the history
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 carltongibson/django-filter#1607.
  • Loading branch information
ngnpope committed Sep 4, 2023
1 parent 048d75a commit 8cbbe64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions django/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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 _
Expand Down Expand Up @@ -1403,7 +1403,7 @@ def __eq__(self, other):
return self.value == other


class ModelChoiceIterator(ChoiceIterator):
class ModelChoiceIterator(BaseChoiceIterator):
def __init__(self, field):
self.field = field
self.queryset = field.queryset
Expand Down
6 changes: 3 additions & 3 deletions django/utils/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
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):
Expand All @@ -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.
Expand Down

0 comments on commit 8cbbe64

Please sign in to comment.