summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-12-07 20:08:24 (GMT)
committerGitHub <noreply@github.com>2020-12-07 20:08:24 (GMT)
commit7c797982383ebfd9cca39c480dcf6132979dd06f (patch)
treedf4adc3932cda7a6f21bb71a366541c933d0d23b /Lib/test/test_builtin.py
parentca52aa3ddd949ce2d259b4263344339b56db00b7 (diff)
downloadcpython-7c797982383ebfd9cca39c480dcf6132979dd06f.zip
cpython-7c797982383ebfd9cca39c480dcf6132979dd06f.tar.gz
cpython-7c797982383ebfd9cca39c480dcf6132979dd06f.tar.bz2
bpo-42536: GC track recycled tuples (GH-23623) (GH-23652)
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. (cherry picked from commit 226a012d1cd61f42ecd3056c554922f359a1a35d)
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 4a49826..729f15d 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
@@ -27,7 +28,7 @@ from types import AsyncGeneratorType, FunctionType
from operator import neg
from test.support import (
EnvironmentVarGuard, TESTFN, check_warnings, swap_attr, unlink,
- maybe_get_event_loop_policy)
+ maybe_get_event_loop_policy, cpython_only)
from test.support.script_helper import assert_python_ok
from unittest.mock import MagicMock, patch
try:
@@ -1573,6 +1574,18 @@ class BuiltinTest(unittest.TestCase):
self.assertIs(cm.exception, exception)
+ @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