Skip to content

Commit 79114d1

Browse files
authored
[mypyc] Fix multiple inheritance with a protocol on Python 3.12 (#15572)
Fix the testProtocol test case in mypyc/test-data/run-classes.test. There was a comment indicating that the code that causes the test to fail on 3.12 is required Python versions older than 3.7, so let's remove it. We only support 3.8 and later these days. Work on mypyc/mypyc#995.
1 parent 8c70e80 commit 79114d1

File tree

1 file changed

+0
-36
lines changed

1 file changed

+0
-36
lines changed

mypyc/lib-rt/misc_ops.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,42 +177,6 @@ PyObject *CPyType_FromTemplate(PyObject *template,
177177
if (!name)
178178
goto error;
179179

180-
// If there is a metaclass other than type, we would like to call
181-
// its __new__ function. Unfortunately there doesn't seem to be a
182-
// good way to mix a C extension class and creating it via a
183-
// metaclass. We need to do it anyways, though, in order to
184-
// support subclassing Generic[T] prior to Python 3.7.
185-
//
186-
// We solve this with a kind of atrocious hack: create a parallel
187-
// class using the metaclass, determine the bases of the real
188-
// class by pulling them out of the parallel class, creating the
189-
// real class, and then merging its dict back into the original
190-
// class. There are lots of cases where this won't really work,
191-
// but for the case of GenericMeta setting a bunch of properties
192-
// on the class we should be fine.
193-
if (metaclass != &PyType_Type) {
194-
assert(bases && "non-type metaclasses require non-NULL bases");
195-
196-
PyObject *ns = PyDict_New();
197-
if (!ns)
198-
goto error;
199-
200-
if (bases != orig_bases) {
201-
if (PyDict_SetItemString(ns, "__orig_bases__", orig_bases) < 0)
202-
goto error;
203-
}
204-
205-
dummy_class = (PyTypeObject *)PyObject_CallFunctionObjArgs(
206-
(PyObject *)metaclass, name, bases, ns, NULL);
207-
Py_DECREF(ns);
208-
if (!dummy_class)
209-
goto error;
210-
211-
Py_DECREF(bases);
212-
bases = dummy_class->tp_bases;
213-
Py_INCREF(bases);
214-
}
215-
216180
// Allocate the type and then copy the main stuff in.
217181
t = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
218182
if (!t)

0 commit comments

Comments
 (0)