diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-11 09:58:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-11 09:58:27 (GMT) |
commit | ddca26188d7828ecb762213f4b9c15d44b6048cc (patch) | |
tree | f672d02823b3e9e0530cd2a201bcf44837aff7d5 /Lib/test/test_monitoring.py | |
parent | 7853c769067699c79c0d4fe4967e9d8f8b8b0a5e (diff) | |
download | cpython-ddca26188d7828ecb762213f4b9c15d44b6048cc.zip cpython-ddca26188d7828ecb762213f4b9c15d44b6048cc.tar.gz cpython-ddca26188d7828ecb762213f4b9c15d44b6048cc.tar.bz2 |
[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 52fbcf61b5a70993c2d32332ff0ad9f369d968d3)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Lib/test/test_monitoring.py')
-rw-r--r-- | Lib/test/test_monitoring.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py index 9d0ad6f..4c74389 100644 --- a/Lib/test/test_monitoring.py +++ b/Lib/test/test_monitoring.py @@ -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 |