summaryrefslogtreecommitdiff
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2017-12-14 23:32:56 +0100
committerGitHub <noreply@github.com>2017-12-14 23:32:56 +0100
commit2b5fd1e9ca9318673989e6ccac2c8acadc3809cd (patch)
tree5aa372f821be82c0d17265700364a5c4643d1cd4 /Objects/typeobject.c
parent15a8728415e765f57e37f431f09e5c5821a04063 (diff)
downloadcpython-git-2b5fd1e9ca9318673989e6ccac2c8acadc3809cd.tar.gz
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/typeobject.c')
-rw-r--r--Objects/typeobject.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 73f94e76c9..5403ecb04f 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) {