How to customise PersistentList
2007-11-06
Andrew BettisonHow to customise PersistentList
Andrew Bettison
In the wake of the "PersistentList.data_is" thread that I started, I
would like to let folks know how I ended up achieving what I wanted. It
turns out to be easy to customise PersistentList so that it wraps
another kind of list object other than the builtin "list":
>>> class MyPersistentList(PersistentList):
... data_is = MyList
... def __init__(self, *args, **kwargs):
... self.data = self.data_is(*args, **kwargs)
That's all. The same goes for PersistentDict and PersistentSet. So all
my fuss was for naught.
BTW, would it be worth commenting at the top of PersistentList that it
is implemented by proxying to an encapsulated list object, instead of as
a subclass that inherits from both list and Persistent, because the
latter will not work: it will provoke a layout conflict error from the
cPython interpreter, since both are implemented as C extension modules?
--
Andrew Bettison <andrewb@zip.com.au>