mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #8268: Old-style classes (not just instances) now support weak
references.
This commit is contained in:
parent
26cc99da2a
commit
a57df2cf1d
5 changed files with 29 additions and 2 deletions
|
@ -685,6 +685,26 @@ class ReferencesTestCase(TestBase):
|
|||
# No exception should be raised here
|
||||
gc.collect()
|
||||
|
||||
def test_classes(self):
|
||||
# Check that both old-style classes and new-style classes
|
||||
# are weakrefable.
|
||||
class A(object):
|
||||
pass
|
||||
class B:
|
||||
pass
|
||||
l = []
|
||||
weakref.ref(int)
|
||||
a = weakref.ref(A, l.append)
|
||||
A = None
|
||||
gc.collect()
|
||||
self.assertEqual(a(), None)
|
||||
self.assertEqual(l, [a])
|
||||
b = weakref.ref(B, l.append)
|
||||
B = None
|
||||
gc.collect()
|
||||
self.assertEqual(b(), None)
|
||||
self.assertEqual(l, [a, b])
|
||||
|
||||
|
||||
class SubclassableWeakrefTestCase(TestBase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue