Lines Matching refs:weakref
5 import weakref
110 wr = weakref.ref(o)
126 wr = weakref.ref(f)
135 ref1 = weakref.ref(o, self.callback)
136 ref2 = weakref.ref(o, self.callback)
157 self.ref = weakref.ref(c, callback)
158 ref1 = weakref.ref(c, callback)
163 self.assertRaises(TypeError, weakref.ref, c, callback=None)
168 ref1 = weakref.proxy(o, self.callback)
169 ref2 = weakref.proxy(o, self.callback)
177 self.assertRaises(ReferenceError, bool, weakref.proxy(C()))
182 ref = weakref.ref(o)
192 ref = weakref.ref(o, self.callback)
201 ref1 = weakref.ref(o)
204 proxy = weakref.proxy(o)
205 ref2 = weakref.ref(o)
210 proxy = weakref.proxy(o)
211 ref1 = weakref.ref(o)
212 ref2 = weakref.ref(o)
215 self.assertEqual(weakref.getweakrefcount(o), 2,
218 self.assertEqual(weakref.getweakrefcount(o), 1,
223 proxy1 = weakref.proxy(o)
224 ref = weakref.ref(o)
225 proxy2 = weakref.proxy(o)
231 self.check_proxy(o, weakref.proxy(o))
234 p = weakref.proxy(L)
247 p2 = weakref.proxy(L2)
251 p3 = weakref.proxy(L3)
265 self.assertIn("__bytes__", dir(weakref.proxy(instance)))
266 self.assertEqual(bytes(weakref.proxy(instance)), b"bytes")
273 p = weakref.proxy(o)
283 p = weakref.proxy(o)
297 p = weakref.proxy(o)
312 self.check_shared_without_callback(weakref.ref)
315 self.check_shared_without_callback(weakref.proxy)
337 ref1 = weakref.proxy(o)
341 self.assertIs(type(ref1), weakref.CallableProxyType,
384 f = weakref.proxy(g)
392 self.assertEqual(bool(weakref.proxy(lyst)), bool(lyst))
407 p = weakref.proxy(obj)
422 self.assertEqual("".join(reversed(weakref.proxy(obj))), "cba")
432 self.assertEqual(hash(weakref.proxy(obj)), cool_hash)
436 ref1 = weakref.ref(o)
437 ref2 = weakref.ref(o, self.callback)
438 self.assertEqual(weakref.getweakrefcount(o), 2,
441 proxy1 = weakref.proxy(o)
442 proxy2 = weakref.proxy(o, self.callback)
443 self.assertEqual(weakref.getweakrefcount(o), 4,
447 self.assertEqual(weakref.getweakrefcount(o), 0,
452 self.assertEqual(weakref.getweakrefcount(1), 0,
457 ref1 = weakref.ref(o, self.callback)
458 ref2 = weakref.ref(o, self.callback)
460 self.assertEqual(weakref.getweakrefs(o), [ref2],
464 ref1 = weakref.ref(o, self.callback)
465 ref2 = weakref.ref(o, self.callback)
467 self.assertEqual(weakref.getweakrefs(o), [ref1],
471 self.assertEqual(weakref.getweakrefs(o), [],
475 self.assertEqual(weakref.getweakrefs(1), [],
482 p = weakref.proxy(f)
496 data[weakref.ref(f, remove)] = None
528 wr = weakref.ref(c, lambda ignore: gc.collect())
536 wr = weakref.ref(c1.i, lambda ignore: gc.collect())
563 I.wr = weakref.ref(J, I.acallback)
615 I.wr = weakref.ref(J, I.acallback)
639 c2.wr = weakref.ref(c1, c2.cb)
667 c2.wr = weakref.ref(c1, c2.cb)
695 c1.wr = weakref.ref(c2, c1.acallback)
696 c2.wr = weakref.ref(c1, c2.acallback)
700 wr = weakref.ref(C, C_went_away)
734 c.wr = weakref.ref(d, callback) # this won't trigger
735 d.wr = weakref.ref(callback, d.cb) # ditto
736 external_wr = weakref.ref(callback, safe_callback) # but this will
757 self.check_gc_during_creation(weakref.ref)
760 self.check_gc_during_creation(weakref.proxy)
782 weakref.ref(referenced, callback)
795 ref_from_del = weakref.ref(self)
802 r = weakref.ref(Exception)
812 weakref.ref(int)
813 a = weakref.ref(A, l.append)
824 a = weakref.ref(x)
825 b = weakref.ref(y)
826 c = weakref.ref(z)
827 d = weakref.ref(x)
861 a = weakref.ref(x)
862 b = weakref.ref(y)
875 a = weakref.ref(x)
876 b = weakref.ref(y)
895 wself = weakref.ref(self)
898 self.wparent = weakref.ref(parent, cb)
900 d = weakref.WeakKeyDictionary()
910 ref1 = weakref.ref(x, callback)
913 ref2 = weakref.ref(x)
918 ref = weakref.ref(x, self.callback)
927 ref1 = weakref.ref(x, callback)
935 ref1 = weakref.ref(x, lambda ref: support.gc_collect())
943 class MyRef(weakref.ref):
960 class MyRef(weakref.ref):
964 r2 = weakref.ref(o)
966 self.assertEqual(weakref.getweakrefs(o), [r2, r1])
967 self.assertEqual(weakref.getweakrefcount(o), 2)
969 self.assertEqual(weakref.getweakrefcount(o), 3)
970 refs = weakref.getweakrefs(o)
977 class MyRef(weakref.ref):
983 refs = weakref.getweakrefs(o)
988 class MyRef(weakref.ref):
991 return weakref.ref.__new__(type, ob, callback)
1011 class MyRef(weakref.ref):
1054 r = weakref.WeakMethod(o.some_method)
1055 self.assertIsInstance(r, weakref.ReferenceType)
1063 r = weakref.WeakMethod(o.some_method)
1071 r = weakref.WeakMethod(o.some_method)
1083 r = weakref.WeakMethod(o.some_method, cb)
1099 r = weakref.WeakMethod(o.some_method, cb)
1114 r = weakref.WeakMethod(o.some_method, cb)
1115 wr = weakref.ref(r)
1128 a = weakref.WeakMethod(x.some_method)
1129 b = weakref.WeakMethod(y.some_method)
1130 c = weakref.WeakMethod(x.other_method)
1131 d = weakref.WeakMethod(y.other_method)
1142 e = weakref.WeakMethod(z.some_method)
1143 f = weakref.WeakMethod(z.other_method)
1165 a = weakref.WeakMethod(x.some_method)
1166 b = weakref.WeakMethod(y.some_method)
1167 c = weakref.WeakMethod(y.other_method)
1205 self.check_len_cycles(weakref.WeakKeyDictionary, lambda k: (k, 1))
1208 self.check_len_cycles(weakref.WeakValueDictionary, lambda k: (1, k))
1235 self.check_len_race(weakref.WeakKeyDictionary, lambda k: (k, 1))
1238 self.check_len_race(weakref.WeakValueDictionary, lambda k: (1, k))
1246 self.assertEqual(weakref.getweakrefcount(o), 1)
1264 dict = weakref.WeakValueDictionary()
1276 self.assertEqual(weakref.getweakrefcount(o), 1,
1499 dict = weakref.WeakKeyDictionary({o:364})
1504 dict = weakref.WeakKeyDictionary({o:364})
1505 dict2 = weakref.WeakKeyDictionary(dict)
1509 dict = weakref.WeakKeyDictionary()
1517 dict = weakref.WeakValueDictionary({364:o})
1522 dict = weakref.WeakValueDictionary({364:o})
1523 dict2 = weakref.WeakValueDictionary(dict)
1528 self.assertRaises(TypeError, weakref.WeakValueDictionary.__init__)
1529 self.assertRaises(TypeError, weakref.WeakValueDictionary, {}, {})
1530 self.assertRaises(TypeError, weakref.WeakValueDictionary, (), ())
1534 d = weakref.WeakValueDictionary(**{kw: o})
1539 dict = weakref.WeakValueDictionary()
1564 self.check_popitem(weakref.WeakValueDictionary,
1568 self.check_popitem(weakref.WeakKeyDictionary,
1589 self.check_setdefault(weakref.WeakValueDictionary,
1593 self.check_setdefault(weakref.WeakKeyDictionary,
1616 self.check_update(weakref.WeakValueDictionary,
1619 self.assertRaises(TypeError, weakref.WeakValueDictionary.update)
1620 d = weakref.WeakValueDictionary()
1627 d = weakref.WeakValueDictionary()
1636 wvd1 = weakref.WeakValueDictionary({1: a})
1637 wvd2 = weakref.WeakValueDictionary({1: b, 2: a})
1644 self.assertIs(type(tmp1), weakref.WeakValueDictionary)
1650 self.assertIs(type(tmp2), weakref.WeakValueDictionary)
1657 self.assertIs(type(tmp3), weakref.WeakValueDictionary)
1661 self.assertIs(type(tmp4), weakref.WeakValueDictionary)
1670 self.check_update(weakref.WeakKeyDictionary,
1674 d = weakref.WeakKeyDictionary()
1688 wkd1 = weakref.WeakKeyDictionary({o1: 1, o2: 2})
1689 wkd2 = weakref.WeakKeyDictionary({o3: 3, o1: 4})
1696 self.assertIs(type(tmp1), weakref.WeakKeyDictionary)
1702 self.assertIs(type(tmp2), weakref.WeakKeyDictionary)
1709 self.assertIs(type(tmp3), weakref.WeakKeyDictionary)
1713 self.assertIs(type(tmp4), weakref.WeakKeyDictionary)
1722 d = weakref.WeakValueDictionary()
1733 d = weakref.WeakKeyDictionary()
1751 d = weakref.WeakKeyDictionary()
1792 dict = weakref.WeakValueDictionary()
1796 dict = weakref.WeakKeyDictionary()
1800 d = weakref.WeakValueDictionary()
1808 d = weakref.WeakValueDictionary()
1818 d = weakref.WeakValueDictionary()
1858 self.assertIn(type_, (weakref.WeakKeyDictionary, weakref.WeakValueDictionary))
1873 if type_ is weakref.WeakKeyDictionary:
1891 self.check_threaded_weak_dict_copy(weakref.WeakKeyDictionary, False)
1896 self.check_threaded_weak_dict_copy(weakref.WeakKeyDictionary, True)
1901 self.check_threaded_weak_dict_copy(weakref.WeakValueDictionary, False)
1906 self.check_threaded_weak_dict_copy(weakref.WeakValueDictionary, True)
1910 d = weakref.WeakValueDictionary()
1919 type2test = weakref.WeakValueDictionary
1926 type2test = weakref.WeakKeyDictionary
1949 f = weakref.finalize(a, add, 67, 43, z=89)
1961 f = weakref.finalize(a, add, 67, 43, 89)
1972 f = weakref.finalize(a, add, x=67, y=43, z=89)
1989 f = weakref.finalize(a, fin, 1, 2, func=3, obj=4)
1995 weakref.finalize(a, func=fin, arg=1)
1997 weakref.finalize(obj=a, func=fin, arg=1)
1998 self.assertRaises(TypeError, weakref.finalize, a)
1999 self.assertRaises(TypeError, weakref.finalize)
2005 f1 = weakref.finalize(a, res.append, 'f1')
2006 f2 = weakref.finalize(a, res.append, 'f2')
2007 f3 = weakref.finalize(a, res.append, 'f3')
2008 f4 = weakref.finalize(a, res.append, 'f4')
2009 f5 = weakref.finalize(a, res.append, 'f5')
2042 class MyFinalizer(weakref.finalize):
2051 wr_callback = weakref.ref(callback)
2052 wr_f = weakref.ref(f)
2070 g1 = weakref.finalize(cls, print, 'g1')
2075 f1 = weakref.finalize(cls, print, 'f1', _global_var)
2076 f2 = weakref.finalize(cls, print, 'f2', _global_var)
2077 f3 = weakref.finalize(cls, error)
2078 f4 = weakref.finalize(cls, print, 'f4', _global_var)