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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a failing regression test
  • Loading branch information
brandtbucher committed Dec 29, 2022
commit 5f182009d1533babc139ffdec2eaa495cc13ce6e
21 changes: 21 additions & 0 deletions Lib/test/test_frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gc
import operator
import re
import sys
import textwrap
Expand Down Expand Up @@ -372,6 +373,26 @@ def run(self):
)
sneaky_frame_object = sneaky_frame_object.f_back

def test_entry_frames_are_invisible_during_teardown(self):
class C:
"""A weakrefable class."""

def f():
"""Try to find globals and locals as this frame is being cleared."""
ref = C()
# Ignore the fact that exec(C()) is a nonsense callback. We're only
# using exec here because it tries to access the current frame's
# globals and locals. If it's trying to get those from a shim frame,
# we'll crash before raising:
return weakref.ref(ref, exec)

with support.catch_unraisable_exception() as catcher:
# Call from C, so there is a shim frame directly above f:
weak = operator.call(f) # BOOM!
# Cool, we didn't crash. Check that the callback actually happened:
self.assertIs(catcher.unraisable.exc_type, TypeError)
self.assertIsNone(weak())

@unittest.skipIf(_testcapi is None, 'need _testcapi')
class TestCAPI(unittest.TestCase):
def getframe(self):
Expand Down