File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import gc
2+ import operator
23import re
34import sys
45import textwrap
@@ -372,6 +373,26 @@ def run(self):
372373 )
373374 sneaky_frame_object = sneaky_frame_object .f_back
374375
376+ def test_entry_frames_are_invisible_during_teardown (self ):
377+ class C :
378+ """A weakrefable class."""
379+
380+ def f ():
381+ """Try to find globals and locals as this frame is being cleared."""
382+ ref = C ()
383+ # Ignore the fact that exec(C()) is a nonsense callback. We're only
384+ # using exec here because it tries to access the current frame's
385+ # globals and locals. If it's trying to get those from a shim frame,
386+ # we'll crash before raising:
387+ return weakref .ref (ref , exec )
388+
389+ with support .catch_unraisable_exception () as catcher :
390+ # Call from C, so there is a shim frame directly above f:
391+ weak = operator .call (f ) # BOOM!
392+ # Cool, we didn't crash. Check that the callback actually happened:
393+ self .assertIs (catcher .unraisable .exc_type , TypeError )
394+ self .assertIsNone (weak ())
395+
375396@unittest .skipIf (_testcapi is None , 'need _testcapi' )
376397class TestCAPI (unittest .TestCase ):
377398 def getframe (self ):
You can’t perform that action at this time.
0 commit comments