diff options
author | Ivan Levkivskyi <levkivskyi@gmail.com> | 2017-12-14 22:32:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 22:32:56 (GMT) |
commit | 2b5fd1e9ca9318673989e6ccac2c8acadc3809cd (patch) | |
tree | 5aa372f821be82c0d17265700364a5c4643d1cd4 /Objects/abstract.c | |
parent | 15a8728415e765f57e37f431f09e5c5821a04063 (diff) | |
download | cpython-2b5fd1e9ca9318673989e6ccac2c8acadc3809cd.zip cpython-2b5fd1e9ca9318673989e6ccac2c8acadc3809cd.tar.gz cpython-2b5fd1e9ca9318673989e6ccac2c8acadc3809cd.tar.bz2 |
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.
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); } |