diff options
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 3cb7a32..0105c5d 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); } |