Ticket #15811: deep_copy.patch

File deep_copy.patch, 2.3 KB (added by abki, 4 years ago)

added a test

  • django/utils/functional.py

     
    6767            cls.__dispatch = {}
    6868            for resultclass in resultclasses:
    6969                cls.__dispatch[resultclass] = {}
    70                 for (k, v) in resultclass.__dict__.items():
    71                     # All __promise__ return the same wrapper method, but they
    72                     # also do setup, inserting the method into the dispatch
    73                     # dict.
    74                     meth = cls.__promise__(resultclass, k, v)
    75                     if hasattr(cls, k):
    76                         continue
    77                     setattr(cls, k, meth)
     70                for type_ in reversed(resultclass.mro()):
     71                    for (k, v) in type_.__dict__.items():
     72                        # All __promise__ return the same wrapper method, but they
     73                        # also do setup, inserting the method into the dispatch
     74                        # dict.
     75                        meth = cls.__promise__(resultclass, k, v)
     76                        if hasattr(cls, k):
     77                            continue
     78                        setattr(cls, k, meth)
    7879            cls._delegate_str = str in resultclasses
    7980            cls._delegate_unicode = unicode in resultclasses
    8081            assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types."
  • tests/regressiontests/utils/functional.py

     
    11from django.utils import unittest
    22from django.utils.functional import lazy
     3from django.utils.datastructures import SortedDict
    34
    4 
    55class FunctionalTestCase(unittest.TestCase):
    66    def test_lazy(self):
    77        t = lazy(lambda: tuple(range(3)), list, tuple)
    88        for a, b in zip(t(), range(3)):
    99            self.assertEqual(a, b)
     10
     11    def test_lazy_deep_copy(self):
     12        """test deep copy of class methods by lazy function"""
     13        t = lazy(lambda: SortedDict([('key','value'), (1,1)]), SortedDict)()
     14        self.assertEqual(t[1], 1)
     15        self.assertTrue('key' in t.keys())
Back to Top