Skip to content
Open
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
2 changes: 1 addition & 1 deletion mypyc/irbuild/vtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def compute_vtable(cls: ClassIR) -> None:

all_traits = [t for t in cls.mro if t.is_trait]

for t in [cls] + cls.traits:
for t in [cls] + [t for t in all_traits if t is not cls]:
for fn in itertools.chain(t.methods.values()):
# TODO: don't generate a new entry when we overload without changing the type
if fn == cls.get_method(fn.name, prefer_method=True):
Expand Down
30 changes: 30 additions & 0 deletions mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -5676,3 +5676,33 @@ def test_derived_acyclic() -> None:
assert d.x == 3
assert d.y == "hi"
assert not gc.is_tracked(d)

[case testTraitVtableGrandparentMethod]
from typing import Any
from mypy_extensions import trait, mypyc_attr

@mypyc_attr(allow_interpreted_subclasses=True)
@trait
class Base:
def value(self) -> Any:
return 42

@mypyc_attr(allow_interpreted_subclasses=True)
@trait
class Middle(Base):
pass

@mypyc_attr(allow_interpreted_subclasses=True)
@trait
class Child(Middle):
def derived(self) -> Any:
return self.value()

class Concrete(Child):
pass

[file driver.py]
from native import Concrete
c = Concrete()
assert c.value() == 42
assert c.derived() == 42