Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,11 @@ def emit_attr_defaults_func_call(defaults_fn: FuncIR, self_name: str, emitter: E
The code returns NULL on a raised exception.
"""
emitter.emit_lines(
"if ({}{}((PyObject *){}) == 0) {{".format(
NATIVE_PREFIX, defaults_fn.cname(emitter.names), self_name
"if ({}{}{}((PyObject *){}) == 0) {{".format(
emitter.get_group_prefix(defaults_fn.decl),
NATIVE_PREFIX,
defaults_fn.cname(emitter.names),
self_name,
Comment thread
georgesittas marked this conversation as resolved.
Outdated
),
"Py_DECREF(self);",
"return NULL;",
Expand Down
39 changes: 39 additions & 0 deletions mypyc/test-data/run-multimodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,45 @@ class Parent:
from native import test
test()

[case testIncrementalCrossModuleInheritedAttrDefaults]
# Regression: under separate=True, when only the subclass module is
# recompiled (parent loaded from mypy's incremental cache, so its
# ClassDef.defs.body is empty), the subclass produces no
# __mypyc_defaults_setup of its own and ClassIR.get_method returns
# the parent's. The emitted call must use the cross-group
# exports_<group>. prefix, otherwise the generated C references an
# undeclared symbol and clang/gcc fail to compile.
import other_a

def test() -> None:
c = other_a.Child()
assert c.x == 1
assert c.y == "hello"

[file other_b.py]
class Parent:
x: int = 1
y: str = "hello"

[file other_a.py]
from other_b import Parent

class Child(Parent):
pass

[file other_a.py.2]
from other_b import Parent

class Child(Parent):
pass

def _force_recompile() -> int:
return 1

[file driver.py]
from native import test
test()

[case testExtraOpsFunction_experimental_librt]
from librt.strings import BytesWriter

Expand Down
Loading