-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-132284: Don't wrap base PyCFunction slots on class creation if not overridden #132329
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
Conversation
Do we have a test that something like this continues to work correctly? If not, maybe we should add one: >>> class D(dict):
... pass
...
>>> d = D({None: None})
>>> assert d[None] is None
>>> D.__getitem__ = lambda self, item: 42
>>> assert d[None] == 42 |
This is probably worth an entry in "what's new" in case someone notices something change for some edge case. |
Also note merge conflict. |
Have a look at addition to whatsnew. Not sure if is right place so if you want something else then tell me what to put where or feel free to change as needed. |
Will not wrap slot functions from base classes if they are not explicitly overridden on class creations.
Subclass
__getitem__()
performance even increases a bit from:to:
Rationale for the checks is as follows:
generic == NULL
because not sure of behavior with slots that loop several times liketp_getattr
,tp_setattr
andtp_richcompare
.Py_IS_TYPE(descr, &PyMethodDescr_Type)
because only if setting pre-existing builtin C method.*ptr == ((PyMethodDescrObject *)descr)->d_method->ml_meth
checks both*ptr != NULL
and stuff like: