Skip to content

Commit 3d3cf70

Browse files
committed
Fix a bug causing coercion to HeldClass instances to crash.
1 parent 89f97cc commit 3d3cf70

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

typed_python/PyInstance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class PyInstance {
302302
static PyObject* initializePythonRepresentation(Type* eltType, const init_func& f) {
303303
Instance instance(eltType, f);
304304

305-
return extractPythonObject(instance.data(), instance.type());
305+
return extractPythonObject(instance.data(), instance.type(), false);
306306
}
307307

308308
//initialize a PyInstance for 'eltType'. For ints, floats, etc, with

typed_python/compiler/tests/held_class_interpreter_semantics_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
from flaky import flaky
66

7-
from typed_python import Class, Final, ListOf, Held, Member, PointerTo, pointerTo
7+
from typed_python import Class, Final, ListOf, Held, Member, PointerTo, pointerTo, Function
88
from typed_python.test_util import currentMemUsageMb
99

1010

@@ -22,6 +22,20 @@ def increment(self):
2222

2323

2424
class TestHeldClassInterpreterSemantics(unittest.TestCase):
25+
def test_can_return_held_class_from_typed_function(self):
26+
@Function
27+
def f(x, y) -> H:
28+
return H(x=x, y=y)
29+
30+
res = f(10, 20)
31+
res2 = f(12, 22)
32+
33+
assert res.x == 10
34+
assert res.y == 20
35+
36+
assert res2.x == 12
37+
assert res2.y == 22
38+
2539
def test_list_of_held_class_item_type(self):
2640
assert sys.gettrace() is None
2741

0 commit comments

Comments
 (0)