mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Issue #25935: Garbage collector now breaks reference loops with OrderedDict.
This commit is contained in:
commit
4918b47c64
3 changed files with 29 additions and 13 deletions
|
@ -1,10 +1,12 @@
|
|||
import contextlib
|
||||
import copy
|
||||
import gc
|
||||
import pickle
|
||||
from random import randrange, shuffle
|
||||
import struct
|
||||
import sys
|
||||
import unittest
|
||||
import weakref
|
||||
from collections.abc import MutableMapping
|
||||
from test import mapping_tests, support
|
||||
|
||||
|
@ -593,6 +595,17 @@ class OrderedDictTests:
|
|||
dict.update(od, [('spam', 1)])
|
||||
self.assertNotIn('NULL', repr(od))
|
||||
|
||||
def test_reference_loop(self):
|
||||
# Issue 25935
|
||||
OrderedDict = self.OrderedDict
|
||||
class A:
|
||||
od = OrderedDict()
|
||||
A.od[A] = None
|
||||
r = weakref.ref(A)
|
||||
del A
|
||||
gc.collect()
|
||||
self.assertIsNone(r())
|
||||
|
||||
|
||||
class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue