From 2b5fd1e9ca9318673989e6ccac2c8acadc3809cd Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 14 Dec 2017 23:32:56 +0100 Subject: 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. --- Objects/abstract.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Objects/abstract.c') diff --git a/Objects/abstract.c b/Objects/abstract.c index 3cb7a32b01..0105c5d169 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -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); } -- cgit v1.2.1