11# Test cases for weakrefs (compile and run)
22
33[case testWeakrefRef]
4- from weakref import ref
4+ from weakref import proxy, ref
55from mypy_extensions import mypyc_attr
66
77@mypyc_attr(native_class=False)
88class Object:
99 """some random weakreffable object"""
10+ def some_meth(self) -> int:
11+ return 1
1012
1113def test_weakref_ref():
1214 obj = Object()
@@ -15,33 +17,13 @@ def test_weakref_ref():
1517 obj = None
1618 assert r() is None, r()
1719
18-
19- [case testWeakrefRefWithCallback]
20- from weakref import ref
21- from mypy_extensions import mypyc_attr
22-
23- @mypyc_attr(native_class=False)
24- class Object:
25- """some random weakreffable object"""
26-
2720def test_weakref_ref_with_callback():
2821 obj = Object()
2922 r = ref(obj, lambda x: x)
3023 assert r() is obj
3124 obj = None
3225 assert r() is None, r()
3326
34-
35- [case testWeakrefProxy]
36- from weakref import proxy
37- from mypy_extensions import mypyc_attr
38-
39- @mypyc_attr(native_class=False)
40- class Object:
41- """some random weakreffable object"""
42- def some_meth(self) -> int:
43- return 1
44-
4527def test_weakref_proxy():
4628 obj = Object()
4729 p = proxy(obj)
@@ -52,19 +34,6 @@ def test_weakref_proxy():
5234 with assertRaises(ReferenceError):
5335 p.some_meth()
5436
55- [builtins fixtures/test-weakref.pyi]
56-
57-
58- [case testWeakrefProxyWithCallback]
59- from weakref import proxy
60- from mypy_extensions import mypyc_attr
61-
62- @mypyc_attr(native_class=False)
63- class Object:
64- """some random weakreffable object"""
65- def some_meth(self) -> int:
66- return 1
67-
6837def test_weakref_proxy_with_callback():
6938 obj = Object()
7039 p = proxy(obj, lambda x: x)
0 commit comments