diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2013-04-13 14:45:44 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2013-04-13 14:45:44 (GMT) |
commit | 556e94b8fe068d1d58064fe84467e0620b87f9ed (patch) | |
tree | 8d6d21319dd056b30cb089d645ba8a0f729c39f7 /Lib | |
parent | 548677bb8ce759395e2512420c03ccb184a77bf5 (diff) | |
download | cpython-556e94b8fe068d1d58064fe84467e0620b87f9ed.zip cpython-556e94b8fe068d1d58064fe84467e0620b87f9ed.tar.gz cpython-556e94b8fe068d1d58064fe84467e0620b87f9ed.tar.bz2 |
Issue #17643: Add __callback__ attribute to weakref.ref.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_weakref.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index cdd26c7..e32e248 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -802,6 +802,30 @@ class ReferencesTestCase(TestBase): del root gc.collect() + def test_callback_attribute(self): + x = Object(1) + callback = lambda ref: None + ref1 = weakref.ref(x, callback) + self.assertIs(ref1.__callback__, callback) + + ref2 = weakref.ref(x) + self.assertIsNone(ref2.__callback__) + + def test_callback_attribute_after_deletion(self): + x = Object(1) + ref = weakref.ref(x, self.callback) + self.assertIsNotNone(ref.__callback__) + del x + support.gc_collect() + self.assertIsNone(ref.__callback__) + + def test_set_callback_attribute(self): + x = Object(1) + callback = lambda ref: None + ref1 = weakref.ref(x, callback) + with self.assertRaises(AttributeError): + ref1.__callback__ = lambda ref: None + class SubclassableWeakrefTestCase(TestBase): |