Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12506 - 'lazy' fails when there are multiple expected classes …

…with the same method

Thanks to Alex for report and patch



git-svn-id: http://code.djangoproject.com/svn/django/trunk@12104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bcef28349a52ff16c9c022b2722138ee9fe62a81 1 parent 4d6c66d
Luke Plant authored January 05, 2010
6  django/utils/functional.py
@@ -167,9 +167,13 @@ def __prepare_class__(cls):
167 167
             for resultclass in resultclasses:
168 168
                 cls.__dispatch[resultclass] = {}
169 169
                 for (k, v) in resultclass.__dict__.items():
  170
+                    # All __promise__ return the same wrapper method, but they
  171
+                    # also do setup, inserting the method into the dispatch
  172
+                    # dict.
  173
+                    meth = cls.__promise__(resultclass, k, v)
170 174
                     if hasattr(cls, k):
171 175
                         continue
172  
-                    setattr(cls, k, cls.__promise__(resultclass, k, v))
  176
+                    setattr(cls, k, meth)
173 177
             cls._delegate_str = str in resultclasses
174 178
             cls._delegate_unicode = unicode in resultclasses
175 179
             assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types."
10  tests/regressiontests/utils/functional.py
... ...
@@ -0,0 +1,10 @@
  1
+from unittest import TestCase
  2
+
  3
+from django.utils.functional import lazy
  4
+
  5
+
  6
+class FunctionalTestCase(TestCase):
  7
+    def test_lazy(self):
  8
+        t = lazy(lambda: tuple(range(3)), list, tuple)
  9
+        for a, b in zip(t(), range(3)):
  10
+            self.assertEqual(a, b)
1  tests/regressiontests/utils/tests.py
@@ -12,6 +12,7 @@
12 12
 import itercompat
13 13
 
14 14
 from decorators import DecoratorFromMiddlewareTests
  15
+from functional import FunctionalTestCase
15 16
 
16 17
 # We need this because "datastructures" uses sorted() and the tests are run in
17 18
 # the scope of this module.

0 notes on commit bcef283

Please sign in to comment.
Something went wrong with that request. Please try again.