Skip to content

Commit 193c16c

Browse files
committed
Add minimal repro of crash as a test
1 parent e1182c7 commit 193c16c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_peepholer.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dis
2+
import gc
23
from itertools import combinations, product
34
import opcode
45
import sys
@@ -2613,6 +2614,22 @@ def test_send(self):
26132614
]
26142615
self.cfg_optimization_test(insts, expected, consts=[None])
26152616

2617+
def test_del_in_finally(self):
2618+
# This loads `obj` onto the stack, executes `del obj`, then returns the
2619+
# `obj` from the stack. See gh-133371 for more details.
2620+
def create_obj():
2621+
obj = [42]
2622+
try:
2623+
return obj
2624+
finally:
2625+
del obj
2626+
2627+
obj = create_obj()
2628+
# The crash in the linked issue happens while running GC during
2629+
# interpreter finalization, so run it here manually.
2630+
gc.collect()
2631+
self.assertEqual(obj, [42])
2632+
26162633

26172634

26182635
if __name__ == "__main__":

0 commit comments

Comments
 (0)