[Python-checkins] r63761 - in python/branches/okkoto-sizeof: Lib/test/test_sys.py Objects/typeobject.c Python/sysmodule.c
Nick Coghlan
ncoghlan at gmail.com
Thu May 29 12:55:43 CEST 2008
robert.schuppenies wrote:
> Author: robert.schuppenies
> Date: Wed May 28 17:52:55 2008
> New Revision: 63761
>
> Log:
> going for the less-than-ideal solution: special case handling in
> sys.getsizeof() and type.__sizeof__() as CLASS_METH
What you're encountering here is known as 'metaclass confusion' - you
*always* want to run the __sizeof__ implementation from the object's
actual type, but the normal attribute lookup process doesn't work that
way for instances of type.
The way to avoid this confusion is to invoke type(obj).__sizeof__(obj)
rather than attempting to invoke obj.__sizeof__() directly.
I'd suggest seeing how you go with changing __sizeof__ back to a normal
method and implementing the C equivalent of type(obj).__sizeof__(obj) to
actually make the method call in sys_getsizeof (see PyObject_Format in
Objects/abstract.c for an example of how to do this).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-checkins
mailing list