gh-143732: allow dict subclasses to be specialized (GH-148128)

This commit is contained in:
Kumar Aditya 2026-05-04 14:09:03 +05:30 committed by GitHub
parent de1769f700
commit 5847931d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 461 additions and 206 deletions

View file

@ -1595,7 +1595,9 @@ _Py_Specialize_StoreSubscr(_PyStackRef container_st, _PyStackRef sub_st, _Py_COD
return;
}
}
if (container_type == &PyDict_Type) {
if (container_type->tp_as_mapping != NULL &&
container_type->tp_as_mapping->mp_ass_subscript == _PyDict_StoreSubscript)
{
specialize(instr, STORE_SUBSCR_DICT);
return;
}
@ -2429,7 +2431,9 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
}
}
}
if (PyAnyDict_CheckExact(lhs)) {
if (Py_TYPE(lhs)->tp_as_mapping != NULL &&
Py_TYPE(lhs)->tp_as_mapping->mp_subscript == _PyDict_Subscript)
{
specialize(instr, BINARY_OP_SUBSCR_DICT);
return;
}