[Persistence-sig] "Straw Baby" Persistence API
Steve Menard
smenard@bigfoot.com
Mon, 22 Jul 2002 11:44:10 -0400
At 11:02 AM 7/22/2002 -0400, Jeremy Hylton wrote:
> >>>>> "SM" == Steve Menard <smenard@bigfoot.com> writes:
>
> GvR> But perhaps these should be rewritten to derive from dict and
> GvR> list instead of UserDict and UserList?
> >>
> >> One small comment. (I owe more substantial comment on Phillip's
> >> earlier proposals.) The persistent versions of dict and list
> >> can't extend the builtin types, because they need to hook
> >> __getitem__() and __setitem__(). The overridden methods may not
> >> be called if we extend the builtin types.
> >>
>
> SM> hum, if those method are not guaranteed to be called by
> SM> subclassing dict or list, then there is something broken. Either
> SM> that or there is a subtle thing I do not understand.
>
>The latter. For performance reasons, most C code uses calls like
>PyDict_GetItem(), which operates directly on the C representation of a
>dict. If you inherit from dict, you'll get the same C representation
>for your object. That allows PyDict_GetItem() to be called, but
>doesn't arrange to call your __getitem__() method. The indirection
>required to invoke a subclass's __getitem__() would cause serious
>performance problems.
Ok, makes sense. Since it is unsafe to override those methods, perhaps it
should be disallowed then. Because we get different behavior when obj[x] is
called from C and when called from Python.
>Normally Guido only recommends inheriting from dict to add new
>behavior (as opposed to customizing existing behavior).
Steve