Code

Ticket #15811: deep_lazy.diff

File deep_lazy.diff, 1.5 KB (added by abki, 3 years ago)

patch that deeply "copy" a class methods

Line 
1Index: django/utils/functional.py
2===================================================================
3--- django/utils/functional.py  (révision 16025)
4+++ django/utils/functional.py  (copie de travail)
5@@ -67,14 +67,15 @@
6             cls.__dispatch = {}
7             for resultclass in resultclasses:
8                 cls.__dispatch[resultclass] = {}
9-                for (k, v) in resultclass.__dict__.items():
10-                    # All __promise__ return the same wrapper method, but they
11-                    # also do setup, inserting the method into the dispatch
12-                    # dict.
13-                    meth = cls.__promise__(resultclass, k, v)
14-                    if hasattr(cls, k):
15-                        continue
16-                    setattr(cls, k, meth)
17+                for type_ in reversed(resultclass.mro()):
18+                    for (k, v) in type_.__dict__.items():
19+                        # All __promise__ return the same wrapper method, but they
20+                        # also do setup, inserting the method into the dispatch
21+                        # dict.
22+                        meth = cls.__promise__(resultclass, k, v)
23+                        if hasattr(cls, k):
24+                            continue
25+                        setattr(cls, k, meth)
26             cls._delegate_str = str in resultclasses
27             cls._delegate_unicode = unicode in resultclasses
28             assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types."