diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h index 83607281e974..8379486355c8 100644 --- a/mypyc/lib-rt/CPy.h +++ b/mypyc/lib-rt/CPy.h @@ -147,6 +147,11 @@ static PyObject *CPyType_FromTemplate(PyTypeObject *template_, if (!ns) goto error; + if (bases != orig_bases) { + if (PyDict_SetItemString(ns, "__orig_bases__", orig_bases) < 0) + goto error; + } + dummy_class = (PyTypeObject *)PyObject_CallFunctionObjArgs( (PyObject *)metaclass, name, bases, ns, NULL); Py_DECREF(ns); diff --git a/mypyc/test-data/run-classes.test b/mypyc/test-data/run-classes.test index a909f64def12..4d012ec425ac 100644 --- a/mypyc/test-data/run-classes.test +++ b/mypyc/test-data/run-classes.test @@ -438,7 +438,7 @@ assert a.foo() == 11 assert foo() == 21 [case testGenericClass] -from typing import TypeVar, Generic +from typing import TypeVar, Generic, Sequence T = TypeVar('T') class C(Generic[T]): x: T @@ -449,6 +449,12 @@ class C(Generic[T]): def set(self, y: T) -> None: self.x = y +# Test subclassing generic classes both with and without a generic param +class A(Sequence[int]): + pass +class B(Sequence[T]): + pass + def f(c: C[int]) -> int: y = c.get() d = C[int](2) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy