From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 21 Jan 2026 11:02:35 +0000 (+0100) Subject: [3.14] 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=aa223bdec6f631aa8213289681c6cb6a7077c741;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-144085: Add `{gi,cr}_suspended` to `inspect` comments and `generator/coroutine` tests (GH-144086) (#144104) gh-144085: Add `{gi,cr}_suspended` to `inspect` comments and `generator/coroutine` tests (GH-144086) (cherry picked from commit 4ef30a5871db2043712945e64f33af81938d68dc) Co-authored-by: Yongtao Huang --- diff --git a/Lib/inspect.py b/Lib/inspect.py index 385fbc686b62..3cee85f39a61 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -348,6 +348,7 @@ 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 __iter__() defined to support iteration over container diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index fc26e71ffcb6..a478fd5a4795 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -2240,8 +2240,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) @@ -2250,14 +2250,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() @@ -2376,7 +2379,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) @@ -2439,8 +2442,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):