durusmail: durus-users: subclassing PeristentDict
subclassing PeristentDict
2006-02-06
2006-02-06
2006-02-06
subclassing PeristentDict
David Binger
2006-02-06
On Feb 5, 2006, at 7:36 PM, Jeff Bauer wrote:

> Running code to store a derived PersistentDict:
>
>     class Staff(PersistentDict):
>         pass
>
> Produces the following error:
>
>   AttributeError: 'Staff' object has no attribute 'data'
>
> I'm familiar enough with old-style UserDict/UserList to
> know that I've got to add the following:
>
>     class Staff(PersistentDict):
>         def __init__(self):
>             PersistentDict.__init__(self)
>
> However, I'm wondering if the error makes sense to
> someone just getting started.  Comments?  FAQ fodder?

I assume that the non-working Staff class had an
__init__ implementation that did not call
PersistentDict.__init__.  Am I right about that?

We usually avoid subclassing the basic container classes.
Our common pattern is to make a special purpose class that
has, say, a PersistentDict as an attribute value.
There are advantages and disadvantages to this, but one
advantage is that it avoids the possible confusion
that you point out.





reply