New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make __sizeof__ for builtin types more subclass friendly #69607
Comments
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. |
New changeset 71d6755145ae by Serhiy Storchaka in branch '3.5': New changeset 4a47e998c40a by Serhiy Storchaka in branch 'default': New changeset be3998aed1e7 by Serhiy Storchaka in branch '2.7': |
Committed with improved tests. |
New changeset a1388dbdd293 by Serhiy Storchaka in branch '3.5': New changeset ab97ff838e11 by Serhiy Storchaka in branch '2.7': New changeset 5115f39cc59f by Serhiy Storchaka in branch 'default': |
Thank you David. Looks related to alignment. Hope this will help. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: