Skip to content

[mypyc] Fix subclassing from abstract generic classes under 3.7 #8121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mypyc/lib-rt/CPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
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