summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-05-05 00:09:51 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-05-05 00:09:51 +0000
commit23b32c75545e1f48e059fae125f94314a99dcb89 (patch)
tree724458e4918ab28c11fa97fee760ed517b19b3f4
parent127f1e4190265a3caf1a0dba6071582256feb2af (diff)
Fixed #15811 - lazy() doesn't take into account methods defined in parents
Thanks to abki for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16157 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/utils/functional.py17
-rw-r--r--tests/regressiontests/utils/functional.py13
2 files changed, 22 insertions, 8 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 9635bf92a6..21463bd575 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -68,14 +68,15 @@ def lazy(func, *resultclasses):
cls.__dispatch = {}
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, meth)
+ for type_ in reversed(resultclass.mro()):
+ for (k, v) in type_.__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, 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."
diff --git a/tests/regressiontests/utils/functional.py b/tests/regressiontests/utils/functional.py
index 763d6964c1..2784ddd7be 100644
--- a/tests/regressiontests/utils/functional.py
+++ b/tests/regressiontests/utils/functional.py
@@ -7,3 +7,16 @@ class FunctionalTestCase(unittest.TestCase):
t = lazy(lambda: tuple(range(3)), list, tuple)
for a, b in zip(t(), range(3)):
self.assertEqual(a, b)
+
+ def test_lazy_base_class(self):
+ """Test that lazy also finds base class methods in the proxy object"""
+
+ class Base(object):
+ def base_method(self):
+ pass
+
+ class Klazz(Base):
+ pass
+
+ t = lazy(lambda: Klazz(), Klazz)()
+ self.assertTrue('base_method' in dir(t))