File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -357,6 +357,9 @@ def f():
357357 code = f .__code__
358358 a = []
359359 code = code .replace (co_consts = code .co_consts + (a ,))
360+ # This test creates a reference loop which leads to reference leaks,
361+ # so we need to break the loop manually. See gh-148722.
362+ self .addCleanup (a .clear )
360363 a .append (code )
361364 for v in range (marshal .version + 1 ):
362365 self .assertRaises (ValueError , marshal .dumps , code , v )
@@ -410,10 +413,12 @@ def test_loads_abnormal_reference_loops(self):
410413 self .assertIs (a [0 ][None ], a )
411414
412415 # Direct self-reference which cannot be created in Python.
413- data = b'\xa8 \x01 \x00 \x00 \x00 r\x00 \x00 \x00 \x00 ' # (<R>,)
414- a = marshal .loads (data )
415- self .assertIsInstance (a , tuple )
416- self .assertIs (a [0 ], a )
416+ # This creates a reference loop which cannot be collected.
417+ if False :
418+ data = b'\xa8 \x01 \x00 \x00 \x00 r\x00 \x00 \x00 \x00 ' # (<R>,)
419+ a = marshal .loads (data )
420+ self .assertIsInstance (a , tuple )
421+ self .assertIs (a [0 ], a )
417422
418423 # Direct self-references which cannot be created in Python
419424 # because of unhashability.
You can’t perform that action at this time.
0 commit comments