mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +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
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue