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 2020 c_function_name = "PyWeakref_NewRef" ,
2121 error_kind = ERR_MAGIC ,
2222)
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 22
33[case testWeakrefRef]
44import pytest # type: ignore [import-not-found]
5- from weakref import ref
5+ from weakref import proxy, ref
66from mypy_extensions import mypyc_attr
77
88@mypyc_attr(native_class=False)
99class Object:
1010 """some random weakreffable object"""
11- pass
11+ def some_meth(self) -> int:
12+ return 1
1213
1314def test_weakref_ref():
1415 obj = Object()
@@ -23,3 +24,19 @@ def test_weakref_ref_with_callback():
2324 assert r() is obj
2425 obj = None
2526 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