Re: extending PersistentList
Jim Fulton <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <CAPDm-FhV3RU4rSws0VOjwe1y6NjMZzi6jRyv6TztLuSyUZjUaw@mail.gmail.com> |
On Fri, May 6, 2016 at 4:21 PM, Lars van Gemerden <[email protected]> wrote: > Hi, > > I have been looking for a way to extend PersistentList in an elegant way. Define elegant? What are you trying to accomplish? > I > tried overriding the abstract methods in MutableSequence but ofcourds that > does not work, because UserList overrides all methods in MutableSequence > (don't know why; speed reasons?). > > I also tried this: > > class ServerFieldList(PersistentList): > > def __init__(self, items, owner=None): > super(ServerFieldList, self).__init__(items) > self.owner = owner > > def _get_changed(self): > return Persistent._get_changed(self) > > def _set_changed(self, value): > Persistent._set_changed(self, value) > self.owner.__dirty__ = True > > def _del_changed(self): > Persistent._del_changed(self) > self.owner.__dirty__ = True > > _p_changed = property(_get_changed, _set_changed, _del_changed) > > > > but directly both calling the _get_changed etc methods in Persistent or > using super(ServerFieldList, self) gives me an AttributeError, while i can > clearly see these methods in Persistent. must have something to do with the > @implementer decorator. I guess you're looking at persistence.py. That is only used when the C implementation isn't used. _get_changed etc are also internal implementation details of the Python implementation. If all you want is an owner attribute a) you don't need a subclass, and b) If you want to create a subclass to add an owner attribute, your __init__ is more than sufficient. You're either over thinking this, or there are some requirement you aren't stating. Jim -- Jim Fulton http://jimfulton.info -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.