mirror of
https://github.com/python/cpython.git
synced 2025-08-11 12:29:34 +00:00
[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:
parent
7853c76906
commit
ddca26188d
6 changed files with 39 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue