Author: lukeplant Date: 2011-05-04 17:09:51 -0700 (Wed, 04 May 2011) New Revision: 16157
Modified: django/trunk/django/utils/functional.py django/trunk/tests/regressiontests/utils/functional.py Log: Fixed #15811 - lazy() doesn't take into account methods defined in parents Thanks to abki for the report and patch. Modified: django/trunk/django/utils/functional.py =================================================================== --- django/trunk/django/utils/functional.py 2011-05-04 23:44:54 UTC (rev 16156) +++ django/trunk/django/utils/functional.py 2011-05-05 00:09:51 UTC (rev 16157) @@ -68,14 +68,15 @@ 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." Modified: django/trunk/tests/regressiontests/utils/functional.py =================================================================== --- django/trunk/tests/regressiontests/utils/functional.py 2011-05-04 23:44:54 UTC (rev 16156) +++ django/trunk/tests/regressiontests/utils/functional.py 2011-05-05 00:09:51 UTC (rev 16157) @@ -7,3 +7,16 @@ 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)) -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.