GH-107724: Fix the signature of PY_THROW callback functions. (GH-107725)

This commit is contained in:
Mark Shannon 2023-08-09 09:30:50 +01:00 committed by GitHub
parent 2fb484e625
commit 52fbcf61b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 18 deletions

View file

@ -743,6 +743,13 @@ class ExceptionHandledRecorder(ExceptionRecorder):
def __call__(self, code, offset, exc):
self.events.append(("handled", type(exc)))
class ThrowRecorder(ExceptionRecorder):
event_type = E.PY_THROW
def __call__(self, code, offset, exc):
self.events.append(("throw", type(exc)))
class ExceptionMonitoringTest(CheckEvents):
@ -888,6 +895,31 @@ class ExceptionMonitoringTest(CheckEvents):
func,
recorders = self.exception_recorders)
def test_throw(self):
def gen():
yield 1
yield 2
def func():
try:
g = gen()
next(g)
g.throw(IndexError)
except IndexError:
pass
self.check_balanced(
func,
recorders = self.exception_recorders)
events = self.get_events(
func,
TEST_TOOL,
self.exception_recorders + (ThrowRecorder,)
)
self.assertEqual(events[0], ("throw", IndexError))
class LineRecorder:
event_type = E.LINE