File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -2518,6 +2518,25 @@ def inner():
2518
2518
# Local variable dict should now be empty.
2519
2519
self .assertEqual (len (inner_frame .f_locals ), 0 )
2520
2520
2521
+ def test_do_not_clear_frame_of_suspended_generator (self ):
2522
+ # See gh-79932
2523
+
2524
+ def f ():
2525
+ try :
2526
+ raise TypeError
2527
+ except Exception as e :
2528
+ yield e
2529
+ yield 42
2530
+
2531
+ def g ():
2532
+ yield from f ()
2533
+
2534
+ gen = g ()
2535
+ e = next (gen )
2536
+ self .assertIsInstance (e , TypeError )
2537
+ traceback .clear_frames (e .__traceback__ )
2538
+ self .assertEqual (next (gen ), 42 )
2539
+
2521
2540
def test_extract_stack (self ):
2522
2541
def extract ():
2523
2542
return traceback .extract_stack ()
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ def clear_frames(tb):
251
251
"Clear all references to local variables in the frames of a traceback."
252
252
while tb is not None :
253
253
try :
254
- tb .tb_frame .clear ()
254
+ tb .tb_frame .clear (True )
255
255
except RuntimeError :
256
256
# Ignore the exception raised if the frame is still executing.
257
257
pass
You can’t perform that action at this time.
0 commit comments