blob: 8d54021c181457be0839c5e6820927adaca167a8 [file] [log] [blame]
Stéphane Wirtelcbb64842019-05-17 11:55:34 +02001.. highlight:: c
Georg Brandl54a3faa2008-01-20 09:30:57 +00002
3.. _gen-objects:
4
5Generator Objects
6-----------------
7
8Generator objects are what Python uses to implement generator iterators. They
9are normally created by iterating over a function that yields values, rather
Yury Selivanov5376ba92015-06-22 12:19:30 -040010than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000011
12
Georg Brandl60203b42010-10-06 10:11:56 +000013.. c:type:: PyGenObject
Georg Brandl54a3faa2008-01-20 09:30:57 +000014
15 The C structure used for generator objects.
16
17
Georg Brandl60203b42010-10-06 10:11:56 +000018.. c:var:: PyTypeObject PyGen_Type
Georg Brandl54a3faa2008-01-20 09:30:57 +000019
Martin Panterd21e0b52015-10-10 10:36:22 +000020 The type object corresponding to generator objects.
Georg Brandl54a3faa2008-01-20 09:30:57 +000021
22
Yury Selivanov5376ba92015-06-22 12:19:30 -040023.. c:function:: int PyGen_Check(PyObject *ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000024
25 Return true if *ob* is a generator object; *ob* must not be *NULL*.
26
27
Yury Selivanov5376ba92015-06-22 12:19:30 -040028.. c:function:: int PyGen_CheckExact(PyObject *ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000029
Yury Selivanov5376ba92015-06-22 12:19:30 -040030 Return true if *ob*'s type is *PyGen_Type*; *ob* must not be *NULL*.
Georg Brandl54a3faa2008-01-20 09:30:57 +000031
32
Georg Brandl60203b42010-10-06 10:11:56 +000033.. c:function:: PyObject* PyGen_New(PyFrameObject *frame)
Georg Brandl54a3faa2008-01-20 09:30:57 +000034
Yury Selivanov5376ba92015-06-22 12:19:30 -040035 Create and return a new generator object based on the *frame* object.
36 A reference to *frame* is stolen by this function. The argument must not be
Georg Brandl54a3faa2008-01-20 09:30:57 +000037 *NULL*.
Yury Selivanov5376ba92015-06-22 12:19:30 -040038
39.. c:function:: PyObject* PyGen_NewWithQualName(PyFrameObject *frame, PyObject *name, PyObject *qualname)
40
41 Create and return a new generator object based on the *frame* object,
42 with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
43 A reference to *frame* is stolen by this function. The *frame* argument
44 must not be *NULL*.