[3.12] GH-107724: Fix the signature of PY_THROW callback functions. (GH-107725) (#107802)

GH-107724: Fix the signature of `PY_THROW` callback functions. (GH-107725)
(cherry picked from commit 52fbcf61b5)

Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
Miss Islington (bot) 2023-08-11 02:58:27 -07:00 committed by GitHub
parent 7853c76906
commit ddca26188d
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