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

@ -168,6 +168,21 @@ PyObject_GetItem(PyObject *o, PyObject *key)
"be integer, not '%.200s'", key);
}
if (PyType_Check(o)) {
PyObject *meth, *result, *stack[2] = {o, key};
_Py_IDENTIFIER(__class_getitem__);
meth = _PyObject_GetAttrId(o, &PyId___class_getitem__);
if (meth) {
result = _PyObject_FastCall(meth, stack, 2);
Py_DECREF(meth);
return result;
}
else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
return NULL;
}
PyErr_Clear();
}
return type_error("'%.200s' object is not subscriptable", o);
}