summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 5897867..c76bcb6 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -282,6 +282,33 @@ gen_iternext(PyGenObject *gen)
}
+static PyObject *
+gen_repr(PyGenObject *gen)
+{
+ return PyUnicode_FromFormat("<%S generator object at %p>",
+ ((PyCodeObject *)gen->gi_code)->co_name,
+ gen);
+}
+
+
+static PyObject *
+gen_get_name(PyGenObject *gen)
+{
+ PyObject *name = ((PyCodeObject *)gen->gi_code)->co_name;
+ Py_INCREF(name);
+ return name;
+}
+
+
+PyDoc_STRVAR(gen__name__doc__,
+"Return the name of the generator's associated code object.");
+
+static PyGetSetDef gen_getsetlist[] = {
+ {"__name__", (getter)gen_get_name, NULL, NULL, gen__name__doc__},
+ {NULL}
+};
+
+
static PyMemberDef gen_memberlist[] = {
{"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), READONLY},
{"gi_running", T_INT, offsetof(PyGenObject, gi_running), READONLY},
@@ -307,7 +334,7 @@ PyTypeObject PyGen_Type = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
- 0, /* tp_repr */
+ (reprfunc)gen_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
@@ -327,7 +354,7 @@ PyTypeObject PyGen_Type = {
(iternextfunc)gen_iternext, /* tp_iternext */
gen_methods, /* tp_methods */
gen_memberlist, /* tp_members */
- 0, /* tp_getset */
+ gen_getsetlist, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */