diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-03-02 23:12:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-02 23:12:54 (GMT) |
commit | 0c2b509f9d1d3a9065bc62c2407e1dc2ed70e9c2 (patch) | |
tree | e4aa312203b373608f069a04d7ad7fd8a61951ea /Lib/test | |
parent | b3b9ade4a3d3fe00d933bcd8fc5c5c755d1024f9 (diff) | |
download | cpython-0c2b509f9d1d3a9065bc62c2407e1dc2ed70e9c2.zip cpython-0c2b509f9d1d3a9065bc62c2407e1dc2ed70e9c2.tar.gz cpython-0c2b509f9d1d3a9065bc62c2407e1dc2ed70e9c2.tar.bz2 |
bpo-39778: Don't traverse weak-reference lists OrderedDict's tp_traverse and tp_clear (GH-18749)
Objects do not own weak references to them directly through the __weakref__ list so these
do not need to be traversed by the GC.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ordered_dict.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py index f337be8..eb0a8f4 100644 --- a/Lib/test/test_ordered_dict.py +++ b/Lib/test/test_ordered_dict.py @@ -753,6 +753,26 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): self.assertEqual(list(unpickled), expected) self.assertEqual(list(it), expected) + @support.cpython_only + def test_weakref_list_is_not_traversed(self): + # Check that the weakref list is not traversed when collecting + # OrderedDict objects. See bpo-39778 for more information. + + gc.collect() + + x = self.OrderedDict() + x.cycle = x + + cycle = [] + cycle.append(cycle) + + x_ref = weakref.ref(x) + cycle.append(x_ref) + + del x, cycle, x_ref + + gc.collect() + class PurePythonOrderedDictSubclassTests(PurePythonOrderedDictTests): |