summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-07-03 04:23:30 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-07-03 04:23:30 (GMT)
commite13f8f3cabda31742beba3dc9e5e170d7bbdbb88 (patch)
tree6a38a8202924e2cc983b91490f32c571bf07ce45 /Objects
parentb32b998bf7ccc8718f1f086f2e3d2658f2e5b224 (diff)
downloadcpython-e13f8f3cabda31742beba3dc9e5e170d7bbdbb88.zip
cpython-e13f8f3cabda31742beba3dc9e5e170d7bbdbb88.tar.gz
cpython-e13f8f3cabda31742beba3dc9e5e170d7bbdbb88.tar.bz2
Issue #24450: Add gi_yieldfrom to generators; cr_await to coroutines.
Patch by Benno Leslie and Yury Selivanov.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genobject.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 3311c4e..00ebbf1 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -552,11 +552,22 @@ gen_set_qualname(PyGenObject *op, PyObject *value)
return 0;
}
+static PyObject *
+gen_getyieldfrom(PyGenObject *gen)
+{
+ PyObject *yf = gen_yf(gen);
+ if (yf == NULL)
+ Py_RETURN_NONE;
+ return yf;
+}
+
static PyGetSetDef gen_getsetlist[] = {
{"__name__", (getter)gen_get_name, (setter)gen_set_name,
PyDoc_STR("name of the generator")},
{"__qualname__", (getter)gen_get_qualname, (setter)gen_set_qualname,
PyDoc_STR("qualified name of the generator")},
+ {"gi_yieldfrom", (getter)gen_getyieldfrom, NULL,
+ PyDoc_STR("object being iterated by yield from, or None")},
{NULL} /* Sentinel */
};
@@ -776,11 +787,22 @@ coro_await(PyCoroObject *coro)
return (PyObject *)cw;
}
+static PyObject *
+coro_get_cr_await(PyCoroObject *coro)
+{
+ PyObject *yf = gen_yf((PyGenObject *) coro);
+ if (yf == NULL)
+ Py_RETURN_NONE;
+ return yf;
+}
+
static PyGetSetDef coro_getsetlist[] = {
{"__name__", (getter)gen_get_name, (setter)gen_set_name,
PyDoc_STR("name of the coroutine")},
{"__qualname__", (getter)gen_get_qualname, (setter)gen_set_qualname,
PyDoc_STR("qualified name of the coroutine")},
+ {"cr_await", (getter)coro_get_cr_await, NULL,
+ PyDoc_STR("object being awaited on, or None")},
{NULL} /* Sentinel */
};