1
0
mirror of https://github.com/django/django.git synced 2025-08-31 14:19:13 +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:
Nick Pope 2023-09-04 12:56:50 +01:00 committed by GitHub
parent a534835c7b
commit 8c8cbe66fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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.