GH-105162: Account for INSTRUMENTED_RESUME in gen.close/throw. (GH-105187)

This commit is contained in:
Mark Shannon 2023-06-02 10:39:38 +01:00 committed by GitHub
parent ee26ca13a1
commit 601ae09f0c
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)