On Mon, Jan 24, 2011 at 1:43 AM, Leonardo Santagada <santag...@gmail.com> wrote:
> On Sat, Jan 22, 2011 at 3:23 PM, Jim Fulton <j...@zope.com> wrote:
>>   a.child == None
>>
>> will because equality comparison will attempt to access
>> methods on the child, which will cause it's activation.
>
> Why would it unghost the object?

I hope, I understand this part, someone please correct me ;)

The unghostify check is done in cPersistence.c in the Per_getattro
function. The Persistence type sets this as:

(getattrofunc)Per_getattro, /* tp_getattro */

This is equivalent to overriding __getattribute__ in Python classes.
It's not set as tp_getattr which would be the same as __getattr__.

__getatttribute__ is called on every attribute access, including
method lookups or lookups in the instance dictionary. __getattr__ is
only called if there's no method on the type, any of its bases and
there's no matching key in the instance dict.

So once you want to compare a ghost to something, there's a couple
lookups for __eq__, __cmp__ or similar API's. Those lookups will cause
the object to be unghostified. The "is" operator compares memory
addresses and doesn't call any method on the type, so it doesn't
unghostify the object.

Hanno
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to