diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-12-05 03:45:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-05 03:45:57 (GMT) |
commit | 226a012d1cd61f42ecd3056c554922f359a1a35d (patch) | |
tree | 86407049a5d2c22b0ce8626407ca106eb3c26afd /Lib/test/test_builtin.py | |
parent | 2de5097ba4c50eba90df55696a7b2e74c93834d4 (diff) | |
download | cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.zip cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.tar.gz cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.tar.bz2 |
bpo-42536: GC track recycled tuples (GH-23623)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector:
- collections.OrderedDict.items
- dict.items
- enumerate
- functools.reduce
- itertools.combinations
- itertools.combinations_with_replacement
- itertools.permutations
- itertools.product
- itertools.zip_longest
- zip
Previously, they could have become untracked by a prior garbage collection.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r-- | Lib/test/test_builtin.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index edb4ec0..8c95737 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -6,6 +6,7 @@ import builtins import collections import decimal import fractions +import gc import io import locale import os @@ -1756,6 +1757,18 @@ class BuiltinTest(unittest.TestCase): l8 = self.iter_error(zip(Iter(3), "AB", strict=True), ValueError) self.assertEqual(l8, [(2, "A"), (1, "B")]) + @support.cpython_only + def test_zip_result_gc(self): + # bpo-42536: zip's tuple-reuse speed trick breaks the GC's assumptions + # about what can be untracked. Make sure we re-track result tuples + # whenever we reuse them. + it = zip([[]]) + gc.collect() + # That GC collection probably untracked the recycled internal result + # tuple, which is initialized to (None,). Make sure it's re-tracked when + # it's mutated and returned from __next__: + self.assertTrue(gc.is_tracked(next(it))) + def test_format(self): # Test the basic machinery of the format() builtin. Don't test # the specifics of the various formatters |