Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f18200

Browse files
committed
Add a failing regression test
1 parent f10f503 commit 5f18200

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lib/test/test_frame.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gc
2+
import operator
23
import re
34
import sys
45
import 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')
376397
class TestCAPI(unittest.TestCase):
377398
def getframe(self):

0 commit comments

Comments
 (0)