Skip to content

Commit

Permalink
Cleanup Python 2 left-overs (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k committed Jun 10, 2020
1 parent 56eaae1 commit 79b4ea7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
10 changes: 2 additions & 8 deletions django_filters/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ def __iter__(self):
yield ("", self.field.empty_label)
if self.field.null_label is not None:
yield (self.field.null_value, self.field.null_label)

# Python 2 lacks 'yield from'
for choice in self.choices:
yield choice
yield from self.choices

def __len__(self):
add = 1 if self.field.empty_label is not None else 0
Expand All @@ -247,10 +244,7 @@ def __iter__(self):
yield next(iterable)
if self.field.null_label is not None:
yield (self.field.null_value, self.field.null_label)

# Python 2 lacks 'yield from'
for value in iterable:
yield value
yield from iterable

def __len__(self):
add = 1 if self.field.null_label is not None else 0
Expand Down
15 changes: 4 additions & 11 deletions tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
from .utils import MockQuerySet


def checkItemsEqual(L1, L2):
"""
TestCase.assertItemsEqual() is not available in Python 2.6.
"""
return len(L1) == len(L2) and sorted(L1) == sorted(L2)


class HelperMethodsTests(TestCase):

@unittest.skip('todo')
Expand Down Expand Up @@ -433,7 +426,7 @@ class Meta:
self.assertEqual(len(F.base_filters), 3)

expected_list = ['price', 'price__gte', 'price__lte', ]
self.assertTrue(checkItemsEqual(list(F.base_filters), expected_list))
self.assertCountEqual(list(F.base_filters), expected_list)

@override_settings(FILTERS_DEFAULT_LOOKUP_EXPR='lte')
def test_meta_fields_dictionary_derived_other_default_lookup(self):
Expand All @@ -447,7 +440,7 @@ class Meta:
self.assertEqual(len(F.base_filters), 3)

expected_list = ['price__exact', 'price__gte', 'price', ]
self.assertTrue(checkItemsEqual(list(F.base_filters), expected_list))
self.assertCountEqual(list(F.base_filters), expected_list)

def test_meta_fields_containing_autofield(self):
class F(FilterSet):
Expand Down Expand Up @@ -476,7 +469,7 @@ class Meta:
self.assertEqual(len(F.base_filters), 2)

expected_list = ['id', 'username']
self.assertTrue(checkItemsEqual(list(F.base_filters), expected_list))
self.assertCountEqual(list(F.base_filters), expected_list)

def test_meta_fields_list_containing_unknown_fields(self):
msg = ("'Meta.fields' must not contain non-model field names: "
Expand Down Expand Up @@ -683,7 +676,7 @@ class Meta:
self.assertEqual(len(F.base_filters), 2)

expected_list = ['published', 'published__year']
self.assertTrue(checkItemsEqual(list(F.base_filters), expected_list))
self.assertCountEqual(list(F.base_filters), expected_list)

def test_declared_filter_multiple_inheritance(self):
class A(FilterSet):
Expand Down

0 comments on commit 79b4ea7

Please sign in to comment.