Commit be92c8b5 authored by Stefan Behnel's avatar Stefan Behnel

add "gi_yieldfrom" to generators and "cr_await" to coroutines (Python issue 24450)

parent 7df9d654
...@@ -1172,6 +1172,8 @@ static PyMethodDef __pyx_Coroutine_methods[] = { ...@@ -1172,6 +1172,8 @@ static PyMethodDef __pyx_Coroutine_methods[] = {
static PyMemberDef __pyx_Coroutine_memberlist[] = { static PyMemberDef __pyx_Coroutine_memberlist[] = {
{(char *) "cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, {(char *) "cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
{(char*) "cr_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
(char*) PyDoc_STR("object being awaited, or None")},
{0, 0, 0, 0, 0} {0, 0, 0, 0, 0}
}; };
...@@ -1288,6 +1290,8 @@ static PyMethodDef __pyx_Generator_methods[] = { ...@@ -1288,6 +1290,8 @@ static PyMethodDef __pyx_Generator_methods[] = {
static PyMemberDef __pyx_Generator_memberlist[] = { static PyMemberDef __pyx_Generator_memberlist[] = {
{(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
{(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
(char*) PyDoc_STR("object being iterated by 'yield from', or None")},
{0, 0, 0, 0, 0} {0, 0, 0, 0, 0}
}; };
......
...@@ -1071,3 +1071,18 @@ def yield_in_return(x): ...@@ -1071,3 +1071,18 @@ def yield_in_return(x):
True True
""" """
return (yield from x) return (yield from x)
def gi_yieldfrom(it):
"""
>>> it = iter([1, 2, 3])
>>> g = gi_yieldfrom(it)
>>> g.gi_yieldfrom is None or "ERROR: %r" % g.gi_yieldfrom
True
>>> next(g)
1
>>> g.gi_yieldfrom is it or "ERROR: %r" % g.gi_yieldfrom
True
"""
x = yield from it
return x
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment