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:
Ivan Levkivskyi 2017-12-14 23:32:56 +01:00 committed by GitHub
parent 15a8728415
commit 2b5fd1e9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 492 additions and 5 deletions

View file

@ -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) {