File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 20
20
c_function_name = "PyWeakref_NewRef" ,
21
21
error_kind = ERR_MAGIC ,
22
22
)
23
+
24
+ new_proxy_op = function_op (
25
+ name = "_weakref.proxy" ,
26
+ arg_types = [object_rprimitive ],
27
+ return_type = object_rprimitive ,
28
+ c_function_name = "PyWeakref_NewProxy" ,
29
+ extra_int_constants = [(0 , pointer_rprimitive )],
30
+ error_kind = ERR_MAGIC ,
31
+ )
32
+
33
+ new_proxy_with_callback_op = function_op (
34
+ name = "_weakref.proxy" ,
35
+ arg_types = [object_rprimitive , object_rprimitive ],
36
+ return_type = object_rprimitive ,
37
+ c_function_name = "PyWeakref_NewProxy" ,
38
+ error_kind = ERR_MAGIC ,
39
+ )
Original file line number Diff line number Diff line change 2
2
3
3
[case testWeakrefRef]
4
4
import pytest # type: ignore [import-not-found]
5
- from weakref import ref
5
+ from weakref import proxy, ref
6
6
from mypy_extensions import mypyc_attr
7
7
8
8
@mypyc_attr(native_class=False)
9
9
class Object:
10
10
"""some random weakreffable object"""
11
- pass
11
+ def some_meth(self) -> int:
12
+ return 1
12
13
13
14
def test_weakref_ref():
14
15
obj = Object()
@@ -23,3 +24,19 @@ def test_weakref_ref_with_callback():
23
24
assert r() is obj
24
25
obj = None
25
26
assert r() is None, r()
27
+
28
+ def test_weakref_proxy():
29
+ obj = Object()
30
+ p = proxy(obj)
31
+ assert p.some_meth() == 1
32
+ obj = None
33
+ with pytest.raises(ReferenceError):
34
+ p.some_meth()
35
+
36
+ def test_weakref_proxy_with_callback():
37
+ obj = Object()
38
+ p = proxy(obj, lambda x: x)
39
+ assert p.some_meth() == 1
40
+ obj = None
41
+ with pytest.raises(ReferenceError):
42
+ p.some_meth()
You can’t perform that action at this time.
0 commit comments