You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
int and set subclass __sizeof__ under-reports the instance dictionary pointer #101266
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.
I'll leave the set part of this to someone more qualified. (@rhettinger?)
For int, I think this is an easy fix; I'll make a PR shortly.
Though oddly enough, I believe the current behaviour in main is correct (though for the wrong reasons), since UserInt.__basicsize__ now matches int.__basicsize__.
Actually, I'm not sure there's any bug here for set: the __dict__ pointer for a UserSet instance is stored in the preheader (the flags for UserSet include Py_TPFLAGS_MANAGED_DICT), and is accounted for there when computing the size with sys.getsizeof.
The int side of this is fixed in main, with the fix backported to 3.11 (but not to 3.10, since the "correct" behaviour is a bit less clear there, and since we didn't backport the previous fix to 3.10).
I believe there's no actual issue on the set side of things (@ionite34 please comment if you disagree), so I'm going to close here.
Activity
mdickinson commentedon Jan 28, 2023
I'll leave the
setpart of this to someone more qualified. (@rhettinger?)For
int, I think this is an easy fix; I'll make a PR shortly.Though oddly enough, I believe the current behaviour in
mainis correct (though for the wrong reasons), sinceUserInt.__basicsize__now matchesint.__basicsize__.mdickinson commentedon Jan 28, 2023
Actually, I'm not sure there's any bug here for
set: the__dict__pointer for aUserSetinstance is stored in the preheader (the flags forUserSetincludePy_TPFLAGS_MANAGED_DICT), and is accounted for there when computing the size withsys.getsizeof.gh-101266: Fix __sizeof__ for subclasses of int (#101394)
[3.11] gh-101266: Fix __sizeof__ for subclasses of int (GH-101394) (#…
mdickinson commentedon Feb 5, 2023
The
intside of this is fixed in main, with the fix backported to 3.11 (but not to 3.10, since the "correct" behaviour is a bit less clear there, and since we didn't backport the previous fix to 3.10).I believe there's no actual issue on the
setside of things (@ionite34 please comment if you disagree), so I'm going to close here.Revert "[3.11] pythongh-101266: Fix __sizeof__ for subclasses of int (p…
[3.11] gh-101266: Revert fix __sizeof__ for subclasses of int (#101638)
Revert "pythongh-101266: Fix __sizeof__ for subclasses of int (python…