[3.12] GH-105162: Account for INSTRUMENTED_RESUME in gen.close/throw. (GH-105187) (#105378)

GH-105162: Account for `INSTRUMENTED_RESUME` in gen.close/throw. (GH-105187)
(cherry picked from commit 601ae09f0c)

Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
Miss Islington (bot) 2023-06-06 07:06:44 -07:00 committed by GitHub
parent 260ba1fcdb
commit 2d9ead219e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 3 deletions

View file

@ -1425,3 +1425,38 @@ class TestUninitialized(unittest.TestCase, MonitoringTestBase):
def test_get_local_events_uninitialized(self):
self.assertEqual(sys.monitoring.get_local_events(TEST_TOOL, self.f.__code__), 0)
class TestRegressions(MonitoringTestBase, unittest.TestCase):
def test_105162(self):
caught = None
def inner():
nonlocal caught
try:
yield
except Exception:
caught = "inner"
yield
def outer():
nonlocal caught
try:
yield from inner()
except Exception:
caught = "outer"
yield
def run():
gen = outer()
gen.send(None)
gen.throw(Exception)
run()
self.assertEqual(caught, "inner")
caught = None
try:
sys.monitoring.set_events(TEST_TOOL, E.PY_RESUME)
run()
self.assertEqual(caught, "inner")
finally:
sys.monitoring.set_events(TEST_TOOL, 0)