-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143552: Fix inspect.getcoroutinestate for generator-based coroutines #143609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2879,6 +2879,17 @@ def _coroutinestate(self): | |
| def test_created(self): | ||
| self.assertEqual(self._coroutinestate(), inspect.CORO_CREATED) | ||
|
|
||
| def test_generator_based_coroutine_introspection(self): | ||
| from inspect import getcoroutinestate | ||
| from types import coroutine | ||
|
|
||
| @coroutine | ||
| def gen_coro(): | ||
| yield | ||
|
|
||
| # Must not raise AttributeError | ||
| getcoroutinestate(gen_coro()) | ||
|
|
||
| def test_suspended(self): | ||
| self.coroutine.send(None) | ||
| self.assertEqual(self._coroutinestate(), inspect.CORO_SUSPENDED) | ||
|
|
@@ -2927,6 +2938,7 @@ async def func(a=None): | |
| {'a': None, 'gencoro': gencoro, 'b': 'spam'}) | ||
|
|
||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change. |
||
| @support.requires_working_socket() | ||
| class TestGetAsyncGenState(unittest.IsolatedAsyncioTestCase): | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -935,6 +935,36 @@ gen_getcode(PyObject *self, void *Py_UNUSED(ignored)) | |
| return _gen_getcode(gen, "gi_code"); | ||
| } | ||
|
|
||
| static PyObject * | ||
| gen_get_cr_frame(PyObject *self, void *closure) | ||
| { | ||
| return gen_getframe((PyObject *)self, closure); | ||
| } | ||
|
|
||
| static PyObject * | ||
| gen_get_cr_code(PyObject *self, void *closure) | ||
| { | ||
| return gen_getcode((PyObject *)self, closure); | ||
| } | ||
|
|
||
| static PyObject * | ||
| gen_get_cr_running(PyObject *self, void *closure) | ||
| { | ||
| return gen_getrunning((PyObject *)self, closure); | ||
| } | ||
|
|
||
| static PyObject * | ||
| gen_get_cr_suspended(PyObject *self, void *closure) | ||
| { | ||
| return gen_getsuspended((PyObject *)self, closure); | ||
| } | ||
|
|
||
| static PyObject * | ||
| gen_get_cr_origin(PyObject *self, void *closure) | ||
| { | ||
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
| static PyGetSetDef gen_getsetlist[] = { | ||
| {"__name__", gen_get_name, gen_set_name, | ||
| PyDoc_STR("name of the generator")}, | ||
|
|
@@ -946,6 +976,11 @@ static PyGetSetDef gen_getsetlist[] = { | |
| {"gi_frame", gen_getframe, NULL, NULL}, | ||
| {"gi_suspended", gen_getsuspended, NULL, NULL}, | ||
| {"gi_code", gen_getcode, NULL, NULL}, | ||
| {"cr_running", gen_get_cr_running, NULL, NULL}, | ||
| {"cr_frame", gen_get_cr_frame, NULL, NULL}, | ||
| {"cr_code", gen_get_cr_code, NULL, NULL}, | ||
| {"cr_suspended", gen_get_cr_suspended, NULL, NULL}, | ||
| {"cr_origin", gen_get_cr_origin, NULL, NULL}, | ||
|
Comment on lines
+979
to
+983
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. Coroutine objects are not generator objects; they should not expose the coroutine interface solely for use in |
||
| {NULL} /* Sentinel */ | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an assertion for what the proper state should be.