@@ -7,7 +7,6 @@ from mypy_extensions import mypyc_attr
7
7
@mypyc_attr(native_class=False)
8
8
class Object:
9
9
"""some random weakreffable object"""
10
- pass
11
10
12
11
def test_weakref_ref():
13
12
obj = Object()
@@ -16,6 +15,20 @@ def test_weakref_ref():
16
15
obj = None
17
16
assert r() is None, r()
18
17
18
+ [file driver.py]
19
+ from native import test_weakref_ref
20
+
21
+ test_weakref_ref()
22
+
23
+
24
+ [case testWeakrefRefWithCallback]
25
+ from weakref import ref
26
+ from mypy_extensions import mypyc_attr
27
+
28
+ @mypyc_attr(native_class=False)
29
+ class Object:
30
+ """some random weakreffable object"""
31
+
19
32
def test_weakref_ref_with_callback():
20
33
obj = Object()
21
34
r = ref(obj, lambda x: x)
@@ -24,7 +37,58 @@ def test_weakref_ref_with_callback():
24
37
assert r() is None, r()
25
38
26
39
[file driver.py]
27
- from native import test_weakref_ref, test_weakref_ref_with_callback
40
+ from native import test_weakref_ref_with_callback
28
41
29
- test_weakref_ref()
30
42
test_weakref_ref_with_callback()
43
+
44
+
45
+ [case testWeakrefProxy]
46
+ import pytest # type: ignore [import-not-found]
47
+ from weakref import proxy
48
+ from mypy_extensions import mypyc_attr
49
+
50
+ @mypyc_attr(native_class=False)
51
+ class Object:
52
+ """some random weakreffable object"""
53
+ def some_meth(self) -> int:
54
+ return 1
55
+
56
+ def test_weakref_proxy():
57
+ obj = Object()
58
+ p = proxy(obj)
59
+ assert obj.some_meth() == 1
60
+ assert p.some_meth() == 1
61
+ obj = None
62
+ with pytest.raises(ReferenceError):
63
+ p.some_meth()
64
+
65
+ [file driver.py]
66
+ from native import test_weakref_proxy
67
+
68
+ test_weakref_proxy()
69
+
70
+
71
+ [case testWeakrefProxyWithCallback]
72
+ import pytest # type: ignore [import-not-found]
73
+ from weakref import proxy
74
+ from mypy_extensions import mypyc_attr
75
+
76
+ @mypyc_attr(native_class=False)
77
+ class Object:
78
+ """some random weakreffable object"""
79
+ def some_meth(self) -> int:
80
+ return 1
81
+
82
+ def test_weakref_proxy_with_callback():
83
+ obj = Object()
84
+ p = proxy(obj, lambda x: x)
85
+ assert obj.some_meth() == 1
86
+ assert p.some_meth() == 1
87
+ obj = None
88
+ with pytest.raises(ReferenceError):
89
+ p.some_meth()
90
+
91
+ [file driver.py]
92
+ from native import test_weakref_proxy_with_callback
93
+
94
+ test_weakref_proxy_with_callback()
0 commit comments