From c3ee0aa669b9bdd5e216e14ff084b1b5747e0efd Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Fri, 31 Jul 2026 17:55:35 +0200 Subject: [PATCH] [mypyc] Fix inconsistent vtable method prefix --- mypyc/codegen/emitclass.py | 4 +--- mypyc/test-data/run-multimodule.test | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index 9ecdea4327d9..ba48a24643b7 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -608,9 +608,7 @@ def generate_vtable( method = entry.shadow_method if shadow and entry.shadow_method else entry.method emitter.emit_line( "(CPyVTableItem){}{}{},".format( - emitter.get_group_prefix(entry.method.decl), - NATIVE_PREFIX, - method.cname(emitter.names), + emitter.get_group_prefix(method.decl), NATIVE_PREFIX, method.cname(emitter.names) ) ) diff --git a/mypyc/test-data/run-multimodule.test b/mypyc/test-data/run-multimodule.test index 672a726ae985..fed4d3606ed9 100644 --- a/mypyc/test-data/run-multimodule.test +++ b/mypyc/test-data/run-multimodule.test @@ -2019,3 +2019,32 @@ class Child(Parent): [file driver.py] from native import test test() + +[case testCompiledSubclassOfCompiledBaseThatAllowsInterpretedSubclasses] +from mypy_extensions import mypyc_attr + +from other import CompiledBase + +class CompiledSubclass(CompiledBase): + def value(self) -> int: + return 1 + +@mypyc_attr(allow_interpreted_subclasses=True) +class CompiledSubclassThatAllowsInterpreted(CompiledBase): + def value(self) -> int: + return 2 + +def test_compiled_subclasses_of_compiled_base_that_allows_interpreted_subclasses() -> None: + c1 = CompiledSubclass() + assert c1.value() == 1 + + c2 = CompiledSubclassThatAllowsInterpreted() + assert c2.value() == 2 + +[file other.py] +from mypy_extensions import mypyc_attr + +@mypyc_attr(allow_interpreted_subclasses=True) +class CompiledBase: + def value(self) -> int: + raise NotImplementedError