From: Yongtao Huang Date: Thu, 22 Jan 2026 09:20:32 +0000 (+0800) Subject: [3.13] gh-144085: Add `{gi,cr}_suspended` to `inspect` comments and `generator/corout... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6acb1628fc045c1bf46f88746328fdea5a8608c;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-144085: Add `{gi,cr}_suspended` to `inspect` comments and `generator/coroutine` tests (GH-144086) (#144134) (cherry picked from commit 4ef30a5871db2043712945e64f33af81938d68dc) --- diff --git a/Lib/inspect.py b/Lib/inspect.py index 5a814f97b5b8..cee6a7f18333 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -465,6 +465,8 @@ def isgenerator(object): gi_frame frame object or possibly None once the generator has been exhausted gi_running set to 1 when generator is executing, 0 otherwise + gi_suspended set to 1 when the generator is suspended at a yield point, 0 otherwise + gi_yieldfrom object being iterated by yield from or None next return the next item from the container send resumes the generator and "sends" a value that becomes the result of the current yield-expression diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index cfb92816d735..d7c229151b3a 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -2164,8 +2164,8 @@ class CoroutineTests(unittest.TestCase): self.assertIs(wrapper.__name__, gen.__name__) # Test AttributeErrors - for name in {'gi_running', 'gi_frame', 'gi_code', 'gi_yieldfrom', - 'cr_running', 'cr_frame', 'cr_code', 'cr_await'}: + for name in {'gi_running', 'gi_frame', 'gi_code', 'gi_yieldfrom', 'gi_suspended', + 'cr_running', 'cr_frame', 'cr_code', 'cr_await', 'cr_suspended'}: with self.assertRaises(AttributeError): getattr(wrapper, name) @@ -2174,14 +2174,17 @@ class CoroutineTests(unittest.TestCase): gen.gi_frame = object() gen.gi_code = object() gen.gi_yieldfrom = object() + gen.gi_suspended = object() self.assertIs(wrapper.gi_running, gen.gi_running) self.assertIs(wrapper.gi_frame, gen.gi_frame) self.assertIs(wrapper.gi_code, gen.gi_code) self.assertIs(wrapper.gi_yieldfrom, gen.gi_yieldfrom) + self.assertIs(wrapper.gi_suspended, gen.gi_suspended) self.assertIs(wrapper.cr_running, gen.gi_running) self.assertIs(wrapper.cr_frame, gen.gi_frame) self.assertIs(wrapper.cr_code, gen.gi_code) self.assertIs(wrapper.cr_await, gen.gi_yieldfrom) + self.assertIs(wrapper.cr_suspended, gen.gi_suspended) wrapper.close() gen.close.assert_called_once_with() @@ -2300,7 +2303,7 @@ class CoroutineTests(unittest.TestCase): self.assertIs(wrapper.__await__(), gen) for name in ('__name__', '__qualname__', 'gi_code', - 'gi_running', 'gi_frame'): + 'gi_running', 'gi_frame', 'gi_suspended'): self.assertIs(getattr(foo(), name), getattr(gen, name)) self.assertIs(foo().cr_code, gen.gi_code) @@ -2363,8 +2366,8 @@ class CoroutineTests(unittest.TestCase): self.assertEqual(repr(wrapper), str(wrapper)) self.assertTrue(set(dir(wrapper)).issuperset({ '__await__', '__iter__', '__next__', 'cr_code', 'cr_running', - 'cr_frame', 'gi_code', 'gi_frame', 'gi_running', 'send', - 'close', 'throw'})) + 'cr_frame', 'cr_suspended', 'gi_code', 'gi_frame', 'gi_running', + 'gi_suspended', 'send', 'close', 'throw'})) class FunctionTests(unittest.TestCase):