summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c15
-rw-r--r--Objects/typeobject.c21
2 files changed, 36 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);
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 73f94e7..5403ecb 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2377,6 +2377,27 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
nbases = 1;
}
else {
+ _Py_IDENTIFIER(__mro_entries__);
+ for (i = 0; i < nbases; i++) {
+ tmp = PyTuple_GET_ITEM(bases, i);
+ if (PyType_Check(tmp)) {
+ continue;
+ }
+ tmp = _PyObject_GetAttrId(tmp, &PyId___mro_entries__);
+ if (tmp != NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "type() doesn't support MRO entry resolution; "
+ "use types.new_class()");
+ Py_DECREF(tmp);
+ return NULL;
+ }
+ else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ }
+ else {
+ return NULL;
+ }
+ }
/* Search the bases for the proper metatype to deal with this: */
winner = _PyType_CalculateMetaclass(metatype, bases);
if (winner == NULL) {