GH-94822: Don't specialize when metaclasses are involved#94892
Conversation
|
Thanks for the quick fix. I think this LGTM. IIRC speaking to Mark at EuroPython he had other ideas about this though (something about just blocking non-immutable classes IIRC). Let's wait for his reply on Monday. |
markshannon
left a comment
There was a problem hiding this comment.
Thanks for adding all the extra tests.
Would it make sense to add a function to test.support, so we can replace
for _ in range(1025): can be replaced with for _ in test.support.UntilSpecialized():?
| PyObject *name) | ||
| { | ||
| _PyLoadMethodCache *cache = (_PyLoadMethodCache *)(instr + 1); | ||
| if (!PyType_CheckExact(owner) || _PyType_Lookup(Py_TYPE(owner), name)) { |
There was a problem hiding this comment.
You could safely generalize this to any immutable metaclass.
Py_TYPE(owner)->tp_flags & Py_TPFLAGS_IMMUTABLETYPE
There was a problem hiding this comment.
Just to clarify, you're only referring to the PyType_CheckExact call, right? The _PyType_Lookup call stays?
Wouldn't we also need to add something like Py_TYPE(owner)->tp_getattro == PyType_Type.tp_getattro too to protect against immutable types that define __getattribute__?
There was a problem hiding this comment.
Just to clarify, you're only referring to the PyType_CheckExact call, right?
Yes
Wouldn't we also need to add something like Py_TYPE(owner)->tp_getattro == PyType_Type.tp_getattro too
And probably some other special case I've forgotten.
Let's just stick with the PyType_CheckExact(owner) to be on the safe side.
|
Thanks @brandtbucher for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
|
Sorry, @brandtbucher, I could not cleanly backport this to |
…pythonGH-94892). (cherry picked from commit daf68ba) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
|
GH-94980 is a backport of this pull request to the 3.11 branch. |
This patch changes
LOAD_ATTR_CLASSto fail if the class has a metaclass other thantype, or if the named attribute is present ontypeitself. It also adds a bunch of regression tests for nasty edge-cases when caching class attributes and methods.Supersedes #94863 (see #94863 (comment)).