-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
int
and set
subclass __sizeof__
under-reports the instance dictionary pointer
#101266
Comments
I'll leave the For Though oddly enough, I believe the current behaviour in |
Actually, I'm not sure there's any bug here for Python 3.12.0a4 (main, Jan 20 2023, 16:04:05) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class UserSet(set): pass
...
>>> s = {1, 2, 3}
>>> us = UserSet(s)
>>> import sys
>>> sys.getsizeof(us) - sys.getsizeof(s)
16 |
Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary. <!-- gh-issue-number: gh-101266 --> * Issue: gh-101266 <!-- /gh-issue-number -->
…101579) Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary. (Manual backport of #101394 to the Python 3.11 branch.)
The I believe there's no actual issue on the |
…ythonGH-101394) (python#101579)" This reverts commit cf89c16.
Bug report
Most built-in types, when subclassed, will have a
__sizeof__
that is 8 (pointer size) larger than the parent object, due to having an instance dictionary.This is unexpectedly, not the case for
int
andset
, which exactly match the original__sizeof__
As a result this makes
__dictoffset__
usages incorrect as wellYour environment
Linked PRs
test_importlib
refleak onaarch64 RHEL8
#101394 #101847The text was updated successfully, but these errors were encountered: