Skip to content

Commit e61adea

Browse files
authored
[mypyc] Add test for incremental builtin_base class construction across groups (#21524)
The fix for this was included in #21369, but no dedicated test was added. This adds `testIncrementalBuiltinBaseClassConstruction` to `run-multimodule.test`: three modules compiled with `separate=True`, where step 2 changes a helper module's signature to force the caller to be recompiled while the exception module is only loaded from cache.
1 parent 55ee0bd commit e61adea

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎mypyc/test-data/run-multimodule.test‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,47 @@ class Base:
17341734
from native import make_child
17351735
assert make_child(7) == "child(7)"
17361736
assert make_child(-1) == "child(-1)"
1737+
1738+
[case testIncrementalBuiltinBaseClassConstruction]
1739+
# Regression: builtin_base classes (Exception subclasses) were unconditionally
1740+
# added to func_to_decl in load_type_map, causing cross-group call sites to
1741+
# emit CPyDef instead of CPyType for the constructor.
1742+
from other_errors import MyError
1743+
from other_util import process
1744+
1745+
def run(value: str) -> None:
1746+
if not value:
1747+
raise MyError("empty")
1748+
1749+
def compute(x: str) -> str:
1750+
result = process(x)
1751+
if not result:
1752+
raise MyError("no result")
1753+
return result
1754+
1755+
[file other_errors.py]
1756+
class MyError(Exception):
1757+
pass
1758+
1759+
[file other_util.py]
1760+
def process(x: str) -> str:
1761+
return x
1762+
1763+
[file other_util.py.2]
1764+
def process(x: str, flag: bool = False) -> str:
1765+
return x.strip()
1766+
1767+
[file driver.py]
1768+
from native import run, compute
1769+
try:
1770+
run("")
1771+
except Exception as e:
1772+
print(str(e))
1773+
print(compute("hello"))
1774+
1775+
[out]
1776+
empty
1777+
hello
1778+
[out2]
1779+
empty
1780+
hello

0 commit comments

Comments
 (0)