This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author schuppenies
Recipients facundobatista, georg.brandl, gvanrossum, loewis, rhettinger, schuppenies
Date 2008-05-28.07:35:51
SpamBayes Score 0.011711997
Marked as misclassified No
Message-id <>
I tried to implement a magic method __sizeof__() for the type object 
which should be callable for type objects and type itself.
But calling __sizeof__ results in an error message

>>> type.__sizeof__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor '__sizeof__' of 'type' object needs an argument

Debugging it I found that type_getattro will (1) look for the
attribute in the metatype, (2) look in tp_dict of this type, and (3)
use the descriptor from the metatype.

I actually want it to perform (3), but since type is its own
metatype (2) will be triggered. This then results in the need for an
argument. The same behavior occurs for all type instances, i.e. classes.

Is my understanding correct? How would it be possible to invoke
__sizeof__() on the type 'type' and not on the object 'type'?

My first approach did the same for object, that is a magic __sizeof__() 
method linked to object, but it gets ignored when invoked on classes or
Now from my understanding everything is an object, thus also
classes and types. isinstance seems to agree with me

>>> >>> isinstance(int, object)

Any suggestions on that?

Date User Action Args
2008-05-28 07:35:59schuppeniessetspambayes_score: 0.011712 -> 0.011711997
recipients: + schuppenies, gvanrossum, loewis, georg.brandl, rhettinger, facundobatista
2008-05-28 07:35:58schuppeniessetspambayes_score: 0.011712 -> 0.011712
messageid: <>
2008-05-28 07:35:56schuppenieslinkissue2898 messages
2008-05-28 07:35:55schuppeniescreate