[Zodb-checkins] CVS: Zope3/lib/python/Persistence - patch.py:1.6
Jeremy Hylton
jeremy@zope.com
Fri, 22 Nov 2002 15:08:22 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv23954/Persistence
Modified Files:
patch.py
Log Message:
Preserve MRO linearizability when add Persistent to bases.
=== Zope3/lib/python/Persistence/patch.py 1.5 => 1.6 ===
--- Zope3/lib/python/Persistence/patch.py:1.5 Fri Nov 22 11:54:38 2002
+++ Zope3/lib/python/Persistence/patch.py Fri Nov 22 15:08:21 2002
@@ -124,11 +124,24 @@
class TypeWrapper(Wrapper):
def unwrap(self, bases, dict):
- # Must add Persistent to the list of bases so that type (the
+ # XXX Add Persistent to the list of bases so that type (the
# base class of PersistentClassMetaClass) will create the
# correct C layout.
- return PersistentClassMetaClass(self._obj.__name__,
- bases + (Persistent,), dict)
+
+ # We must maintain a linearizable MRO when adding Persistent
+ # to list of bases. In particular, object is in Persistent's
+ # __bases__ to Persistent must occur before object in the
+ # new class's __bases__.
+
+ if not Persistent in bases:
+ if object in bases:
+ L = list(bases)
+ i = L.index(object)
+ newbases = bases[:i] + (Persistent,) + bases[i:]
+ else:
+ newbases = bases + (Persistent,)
+
+ return PersistentClassMetaClass(self._obj.__name__, newbases, dict)
class Pickler(pickle.Pickler):