mirror of https://github.com/django/django.git
Fixed #23838 -- added missing `__iter__` to LazyObject
This commit is contained in:
parent
888c9b6429
commit
a5b225084f
|
@ -298,11 +298,11 @@ class LazyObject(object):
|
||||||
__ne__ = new_method_proxy(operator.ne)
|
__ne__ = new_method_proxy(operator.ne)
|
||||||
__hash__ = new_method_proxy(hash)
|
__hash__ = new_method_proxy(hash)
|
||||||
|
|
||||||
# Dictionary methods support
|
# List/Tuple/Dictionary methods support
|
||||||
__getitem__ = new_method_proxy(operator.getitem)
|
__getitem__ = new_method_proxy(operator.getitem)
|
||||||
__setitem__ = new_method_proxy(operator.setitem)
|
__setitem__ = new_method_proxy(operator.setitem)
|
||||||
__delitem__ = new_method_proxy(operator.delitem)
|
__delitem__ = new_method_proxy(operator.delitem)
|
||||||
|
__iter__ = new_method_proxy(iter)
|
||||||
__len__ = new_method_proxy(len)
|
__len__ = new_method_proxy(len)
|
||||||
__contains__ = new_method_proxy(operator.contains)
|
__contains__ = new_method_proxy(operator.contains)
|
||||||
|
|
||||||
|
|
|
@ -165,11 +165,22 @@ class LazyObjectTestCase(TestCase):
|
||||||
del obj_dict['f']
|
del obj_dict['f']
|
||||||
|
|
||||||
def test_iter(self):
|
def test_iter(self):
|
||||||
# LazyObjects don't actually implements __iter__ but you can still
|
# Tests whether an object's custom `__iter__` method is being
|
||||||
# iterate over them because they implement __getitem__
|
# used when iterating over it.
|
||||||
obj = self.lazy_wrap([1, 2, 3])
|
|
||||||
for expected, actual in zip([1, 2, 3], obj):
|
class IterObject(object):
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
def __init__(self, values):
|
||||||
|
self.values = values
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.values)
|
||||||
|
|
||||||
|
original_list = ['test', '123']
|
||||||
|
self.assertEqual(
|
||||||
|
list(self.lazy_wrap(IterObject(original_list))),
|
||||||
|
original_list
|
||||||
|
)
|
||||||
|
|
||||||
def test_pickle(self):
|
def test_pickle(self):
|
||||||
# See ticket #16563
|
# See ticket #16563
|
||||||
|
|
Loading…
Reference in New Issue