summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-11-20 16:41:20 (GMT)
committerGitHub <noreply@github.com>2024-11-20 16:41:20 (GMT)
commitaea0c586d181abb897511b6b46d28bfbe4858f79 (patch)
treec80958b80c4cf5eeb75898c89b868440a2174b99 /Lib/test/test_dict.py
parent7191b7662efcd79f2f19821c9b9fa2155df6f698 (diff)
downloadcpython-aea0c586d181abb897511b6b46d28bfbe4858f79.zip
cpython-aea0c586d181abb897511b6b46d28bfbe4858f79.tar.gz
cpython-aea0c586d181abb897511b6b46d28bfbe4858f79.tar.bz2
GH-127010: Don't lazily track and untrack dicts (GH-127027)
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py109
1 files changed, 0 insertions, 109 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 4030716..c94dc2d 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -880,115 +880,6 @@ class DictTest(unittest.TestCase):
gc.collect()
self.assertIs(ref(), None, "Cycle was not collected")
- def _not_tracked(self, t):
- # Nested containers can take several collections to untrack
- gc.collect()
- gc.collect()
- self.assertFalse(gc.is_tracked(t), t)
-
- def _tracked(self, t):
- self.assertTrue(gc.is_tracked(t), t)
- gc.collect()
- gc.collect()
- self.assertTrue(gc.is_tracked(t), t)
-
- def test_string_keys_can_track_values(self):
- # Test that this doesn't leak.
- for i in range(10):
- d = {}
- for j in range(10):
- d[str(j)] = j
- d["foo"] = d
-
- @support.cpython_only
- def test_track_literals(self):
- # Test GC-optimization of dict literals
- x, y, z, w = 1.5, "a", (1, None), []
-
- self._not_tracked({})
- self._not_tracked({x:(), y:x, z:1})
- self._not_tracked({1: "a", "b": 2})
- self._not_tracked({1: 2, (None, True, False, ()): int})
- self._not_tracked({1: object()})
-
- # Dicts with mutable elements are always tracked, even if those
- # elements are not tracked right now.
- self._tracked({1: []})
- self._tracked({1: ([],)})
- self._tracked({1: {}})
- self._tracked({1: set()})
-
- @support.cpython_only
- def test_track_dynamic(self):
- # Test GC-optimization of dynamically-created dicts
- class MyObject(object):
- pass
- x, y, z, w, o = 1.5, "a", (1, object()), [], MyObject()
-
- d = dict()
- self._not_tracked(d)
- d[1] = "a"
- self._not_tracked(d)
- d[y] = 2
- self._not_tracked(d)
- d[z] = 3
- self._not_tracked(d)
- self._not_tracked(d.copy())
- d[4] = w
- self._tracked(d)
- self._tracked(d.copy())
- d[4] = None
- self._not_tracked(d)
- self._not_tracked(d.copy())
-
- # dd isn't tracked right now, but it may mutate and therefore d
- # which contains it must be tracked.
- d = dict()
- dd = dict()
- d[1] = dd
- self._not_tracked(dd)
- self._tracked(d)
- dd[1] = d
- self._tracked(dd)
-
- d = dict.fromkeys([x, y, z])
- self._not_tracked(d)
- dd = dict()
- dd.update(d)
- self._not_tracked(dd)
- d = dict.fromkeys([x, y, z, o])
- self._tracked(d)
- dd = dict()
- dd.update(d)
- self._tracked(dd)
-
- d = dict(x=x, y=y, z=z)
- self._not_tracked(d)
- d = dict(x=x, y=y, z=z, w=w)
- self._tracked(d)
- d = dict()
- d.update(x=x, y=y, z=z)
- self._not_tracked(d)
- d.update(w=w)
- self._tracked(d)
-
- d = dict([(x, y), (z, 1)])
- self._not_tracked(d)
- d = dict([(x, y), (z, w)])
- self._tracked(d)
- d = dict()
- d.update([(x, y), (z, 1)])
- self._not_tracked(d)
- d.update([(x, y), (z, w)])
- self._tracked(d)
-
- @support.cpython_only
- def test_track_subtypes(self):
- # Dict subtypes are always tracked
- class MyDict(dict):
- pass
- self._tracked(MyDict())
-
def make_shared_key_dict(self, n):
class C:
pass