mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
bpo-32226: Implementation of PEP 560 (core components) (#4732)
This part of the PEP implementation adds support for __mro_entries__ and __class_getitem__ by updating __build_class__ and PyObject_GetItem.
This commit is contained in:
parent
15a8728415
commit
2b5fd1e9ca
7 changed files with 492 additions and 5 deletions
|
@ -2377,6 +2377,27 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
|||
nbases = 1;
|
||||
}
|
||||
else {
|
||||
_Py_IDENTIFIER(__mro_entries__);
|
||||
for (i = 0; i < nbases; i++) {
|
||||
tmp = PyTuple_GET_ITEM(bases, i);
|
||||
if (PyType_Check(tmp)) {
|
||||
continue;
|
||||
}
|
||||
tmp = _PyObject_GetAttrId(tmp, &PyId___mro_entries__);
|
||||
if (tmp != NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"type() doesn't support MRO entry resolution; "
|
||||
"use types.new_class()");
|
||||
Py_DECREF(tmp);
|
||||
return NULL;
|
||||
}
|
||||
else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* Search the bases for the proper metatype to deal with this: */
|
||||
winner = _PyType_CalculateMetaclass(metatype, bases);
|
||||
if (winner == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue