[Persistence-sig] "Straw Baby" Persistence API

Kevin Jacobs jacobs@penguin.theopalgroup.com
Mon, 22 Jul 2002 11:42:11 -0400 (EDT)


On Mon, 22 Jul 2002, Steve Menard wrote:
> Mater of fact, I do not think otherwise. Jeremy said :
> 
> "The overridden methods may not be called if we extend the builtin types."
> 
> Which I think is wrong.

I see what he is saying now -- most of the Python core does a
PyDict_Check(o), not a PyDict_CheckExact(o) to determine if an object is a
real (base) dictionary.  Such code then does PyDict_GetItem/PyDict_SetItem
rather than PyObject_GetItem/PyObject_SetItem, and thus bypass your derived
__getitem__ and __setitem__.

> > > On a side note, as I have said in another post, I have done exactly that,
> > > subclassing dict and list. While my model didn't need to override
> > > __getitem__(), the __setitem__() at least seemed to act properly. In fact
> > > the only problem I have found is that it was not possible to mix __slots__
> > > and dict/list.
> >
> >For all strange and perverse things I've done, slots work just fine when
> >inheriting from list and dict.  Again, can you provide an example of where
> >you found otherwise?
> 
> Ok, my problem was from inheriting both from dict and from my Persistent 
> class. Persistent was using slots. I could dig out or reproduce error 
> message if you're interested.

>From your description, I see what is happening now.  I have a meta-class
that lazily instantiates slots, which may help.  It totally avoids the
problem of layout conflicts, so long as all base classes can have slots
added to them (i.e., not anything that inherits from tuple).

-Kevin

--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19         E-mail: jacobs@theopalgroup.com
Fax:   (216) 986-0714              WWW:    http://www.theopalgroup.com