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 @@ -350,6 +350,9 @@ def f():
350350 code = f .__code__
351351 a = []
352352 code = code .replace (co_consts = code .co_consts + (a ,))
353+ # This test creates a reference loop which leads to reference leaks,
354+ # so we need to break the loop manually. See gh-148722.
355+ self .addCleanup (a .clear )
353356 a .append (code )
354357 for v in range (marshal .version + 1 ):
355358 self .assertRaises (ValueError , marshal .dumps , code , v )
@@ -381,10 +384,12 @@ def test_loads_abnormal_reference_loops(self):
381384 self .assertIs (a [0 ][None ], a )
382385
383386 # Direct self-reference which cannot be created in Python.
384- data = b'\xa8 \x01 \x00 \x00 \x00 r\x00 \x00 \x00 \x00 ' # (<R>,)
385- a = marshal .loads (data )
386- self .assertIsInstance (a , tuple )
387- self .assertIs (a [0 ], a )
387+ # This creates a reference loop which cannot be collected.
388+ if False :
389+ data = b'\xa8 \x01 \x00 \x00 \x00 r\x00 \x00 \x00 \x00 ' # (<R>,)
390+ a = marshal .loads (data )
391+ self .assertIsInstance (a , tuple )
392+ self .assertIs (a [0 ], a )
388393
389394 # Direct self-references which cannot be created in Python
390395 # because of unhashability.
You can’t perform that action at this time.
0 commit comments