From 550e6656d9facd632662b693ce9f4f4ce00781dc Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 29 Sep 2026 16:51:47 +0100 Subject: [PATCH] [mypyc] Fix cross-group constructor calls to cached non-native classes This was broken when using incremental builds. --- mypyc/irbuild/prepare.py | 10 +++++----- mypyc/test-data/run-multimodule.test | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mypyc/irbuild/prepare.py b/mypyc/irbuild/prepare.py index 2902fb2e6351..bf9b81532d54 100644 --- a/mypyc/irbuild/prepare.py +++ b/mypyc/irbuild/prepare.py @@ -210,11 +210,11 @@ def load_type_map(mapper: Mapper, modules: list[MypyFile], deser_ctx: DeserMaps) continue mapper.type_to_ir[node.node] = ir mapper.symbol_fullnames.add(node.node.fullname) - # Trait/builtin-base classes have an ir.ctor FuncDecl - # but no emitted CPyDef_, so a cross-group direct - # call would hit an undefined symbol. Mirror the skip - # in prepare_init_method. - if not ir.is_trait and not ir.builtin_base: + # Non-extension, trait and builtin-base classes have no + # emitted CPyDef_, so a cross-group direct call + # would hit an undefined symbol. Mirror the conditions + # under which prepare_init_method registers a ctor. + if ir.is_ext_class and not ir.is_trait and not ir.builtin_base: mapper.func_to_decl[node.node] = ir.ctor for module in modules: diff --git a/mypyc/test-data/run-multimodule.test b/mypyc/test-data/run-multimodule.test index c87112a78b01..baab2f52ce08 100644 --- a/mypyc/test-data/run-multimodule.test +++ b/mypyc/test-data/run-multimodule.test @@ -1421,6 +1421,27 @@ import native 0 None +[case testIncrementalCompilationWithNonExtClass] +import other_a +[file other_a.py] +from other_b import C +[file other_a.py.2] +from other_b import C +c = C(5) +print(c.x) +[file other_b.py] +from mypy_extensions import mypyc_attr + +@mypyc_attr(native_class=False) +class C: + def __init__(self, x: int) -> None: + self.x = x +[file driver.py] +import native +[out] +[out2] +5 + [case testIncrementalCompilationWithNonClassTypeDef] import other_a [file other_a.py]