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 serhiy.storchaka
Recipients serhiy.storchaka
Date 2015-10-16.16:41:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1445013720.79.0.218203938843.issue25421@psf.upfronthosting.co.za>
In-reply-to
Content
Default __sizeof__() implementation uses tp_basicsize. This makes it to work correctly with most builtin types and types with __slots__ (using __slots__ increases tp_basicsize). But special implementations of __sizeof__() use static object size ('sizeof(XXXObject)'), and return incorrect result for subclasses that increase tp_basicsize. Proposed patch makes __sizeof__() for all subclassable builtin type that support changing object size (i.e. tp_itemsize == 0) to use dynamic size _PyObject_SIZE(Py_TYPE(self)).

Example (with patched code):
>>> class D(dict):
...     __slots__ = 'a', 'b', 'c'
... 
>>> sys.getsizeof({})
144
>>> sys.getsizeof(D())
156

In unpatched Python sys.getsizeof(D()) returns 144.
History
Date User Action Args
2015-10-16 16:42:01serhiy.storchakasetrecipients: + serhiy.storchaka
2015-10-16 16:42:00serhiy.storchakasetmessageid: <1445013720.79.0.218203938843.issue25421@psf.upfronthosting.co.za>
2015-10-16 16:42:00serhiy.storchakalinkissue25421 messages
2015-10-16 16:42:00serhiy.storchakacreate