blob: 0eb5922f6da75f25803ced5b45f0f9cd3e01514a [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
Antonio Cuni315fc522021-01-06 12:38:26 +010025 Return true if *ob* is a generator object; *ob* must not be ``NULL``. This
26 function always succeeds.
Georg Brandl54a3faa2008-01-20 09:30:57 +000027
28
Yury Selivanov5376ba92015-06-22 12:19:30 -040029.. c:function:: int PyGen_CheckExact(PyObject *ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000030
Antonio Cuni315fc522021-01-06 12:38:26 +010031 Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be
32 ``NULL``. This function always succeeds.
Georg Brandl54a3faa2008-01-20 09:30:57 +000033
34
Georg Brandl60203b42010-10-06 10:11:56 +000035.. c:function:: PyObject* PyGen_New(PyFrameObject *frame)
Georg Brandl54a3faa2008-01-20 09:30:57 +000036
Yury Selivanov5376ba92015-06-22 12:19:30 -040037 Create and return a new generator object based on the *frame* object.
38 A reference to *frame* is stolen by this function. The argument must not be
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020039 ``NULL``.
Yury Selivanov5376ba92015-06-22 12:19:30 -040040
41.. c:function:: PyObject* PyGen_NewWithQualName(PyFrameObject *frame, PyObject *name, PyObject *qualname)
42
43 Create and return a new generator object based on the *frame* object,
44 with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
45 A reference to *frame* is stolen by this function. The *frame* argument
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020046 must not be ``NULL``.