Skip to content

Commit

Permalink
Removed usage of deprecated is_iterable util (#1642)
Browse files Browse the repository at this point in the history
Django announced [1] that the `django.utils.itercompat` module is
deprecated since Django 5.1.

Instead, the same behavior can be achieved with an instance comparison
against `Iterable` [2].

[1] https://docs.djangoproject.com/en/dev/releases/5.1/#features-deprecated-in-5-1
[2] https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable
  • Loading branch information
adamantike authored Mar 8, 2024
1 parent a2f7aba commit d0e34ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django_filters/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import OrderedDict
from collections.abc import Iterable
from datetime import timedelta
from itertools import chain

Expand All @@ -7,7 +8,6 @@
from django.db.models import Q
from django.db.models.constants import LOOKUP_SEP
from django.forms.utils import pretty_name
from django.utils.itercompat import is_iterable
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -776,14 +776,14 @@ def normalize_fields(cls, fields):
return OrderedDict(fields)

# convert iterable of values => iterable of pairs (field name, param name)
assert is_iterable(
fields
assert isinstance(
fields, Iterable
), "'fields' must be an iterable (e.g., a list, tuple, or mapping)."

# fields is an iterable of field names
assert all(
isinstance(field, str)
or is_iterable(field)
or isinstance(field, Iterable)
and len(field) == 2 # may need to be wrapped in parens
for field in fields
), "'fields' must contain strings or (field name, param name) pairs."
Expand Down

0 comments on commit d0e34ef

Please sign in to comment.