Loading django/utils/functional.py +5 −1 Original line number Diff line number Diff line Loading @@ -167,9 +167,13 @@ def lazy(func, *resultclasses): for resultclass in resultclasses: cls.__dispatch[resultclass] = {} for (k, v) in resultclass.__dict__.items(): # All __promise__ return the same wrapper method, but they # also do setup, inserting the method into the dispatch # dict. meth = cls.__promise__(resultclass, k, v) if hasattr(cls, k): continue setattr(cls, k, cls.__promise__(resultclass, k, v)) setattr(cls, k, meth) cls._delegate_str = str in resultclasses cls._delegate_unicode = unicode in resultclasses assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types." Loading tests/regressiontests/utils/functional.py 0 → 100644 +10 −0 Original line number Diff line number Diff line from unittest import TestCase from django.utils.functional import lazy class FunctionalTestCase(TestCase): def test_lazy(self): t = lazy(lambda: tuple(range(3)), list, tuple) for a, b in zip(t(), range(3)): self.assertEqual(a, b) tests/regressiontests/utils/tests.py +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import datastructures import dateformat import itercompat from decorators import DecoratorFromMiddlewareTests from functional import FunctionalTestCase # We need this because "datastructures" uses sorted() and the tests are run in # the scope of this module. Loading Loading
django/utils/functional.py +5 −1 Original line number Diff line number Diff line Loading @@ -167,9 +167,13 @@ def lazy(func, *resultclasses): for resultclass in resultclasses: cls.__dispatch[resultclass] = {} for (k, v) in resultclass.__dict__.items(): # All __promise__ return the same wrapper method, but they # also do setup, inserting the method into the dispatch # dict. meth = cls.__promise__(resultclass, k, v) if hasattr(cls, k): continue setattr(cls, k, cls.__promise__(resultclass, k, v)) setattr(cls, k, meth) cls._delegate_str = str in resultclasses cls._delegate_unicode = unicode in resultclasses assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types." Loading
tests/regressiontests/utils/functional.py 0 → 100644 +10 −0 Original line number Diff line number Diff line from unittest import TestCase from django.utils.functional import lazy class FunctionalTestCase(TestCase): def test_lazy(self): t = lazy(lambda: tuple(range(3)), list, tuple) for a, b in zip(t(), range(3)): self.assertEqual(a, b)
tests/regressiontests/utils/tests.py +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import datastructures import dateformat import itercompat from decorators import DecoratorFromMiddlewareTests from functional import FunctionalTestCase # We need this because "datastructures" uses sorted() and the tests are run in # the scope of this module. Loading