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
Support key-sharing dictionaries in subclasses #64836
Comments
PEP-412 shared keys are not created for subclasses in Python 3.3 and 3.4: >>> import sys
>>> class A:
... pass
...
>>> class B(A):
... pass
...
>>> a, b = A(), B()
>>> sys.getsizeof(vars(a))
96
>>> sys.getsizeof(vars(b))
288 (Actual sizes depend on platform and configuration). This patch allows subclasses to share keys: >>> import sys
>>> class A:
... pass
...
>>> class B(A):
... pass
...
>>> a, b = A(), B()
>>> sys.getsizeof(vars(a))
96
>>> sys.getsizeof(vars(b))
96 |
Wow, really? Thanks for finding this! |
Well spotted. I don't think that the line inherit_special() is called from PyType_Ready |
Thanks Mark, I agree. I thought that assigning to tp_dictoffset in inherit_special was redundant with the assignment in inherit_slot and the assignment I added, but I see that COPYSLOT and COPYVAL are slightly different and extension types won't go through type_new. Here's an updated patch. |
This looks good to me. Also, I think this should go into 3.4 |
I think that it's too late for optimizations in Python 3.4 (RC1 is alread out). It can wait Python 3.5, or maybe 3.4.1. |
I agree: definitely not for 3.5, maybe for 3.4.1. |
New changeset 16229573e73e by Antoine Pitrou in branch 'default': |
Thanks. I've committed a patch after augmenting the tests a bit, so it'll be in 3.4.1 as well as 3.5. |
New changeset afae24cb81d9 by Benjamin Peterson in branch '3.4': |
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: