Debian Codegraph @

Doc/c-api/gen.rst

raw
1 .. highlight:: c
2
3 .. _gen-objects:
4
5 Generator Objects
6 -----------------
7
8 Generator objects are what Python uses to implement generator iterators. They
9 are normally created by iterating over a function that yields values, rather
10 than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
11
12
13 .. c:type:: PyGenObject
14
15 The C structure used for generator objects.
16
17
18 .. c:var:: PyTypeObject PyGen_Type
19
20 The type object corresponding to generator objects.
21
22
23 .. c:function:: int PyGen_Check(PyObject *ob)
24
25 Return true if *ob* is a generator object; *ob* must not be ``NULL``. This
26 function always succeeds.
27
28
29 .. c:function:: int PyGen_CheckExact(PyObject *ob)
30
31 Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be
32 ``NULL``. This function always succeeds.
33
34
35 .. c:function:: PyObject* PyGen_New(PyFrameObject *frame)
36
37 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
39 ``NULL``.
40
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
46 must not be ``NULL``.
47
48 .. c:function:: PyCodeObject* PyGen_GetCode(PyGenObject *gen)
49
50 Return a new :term:`strong reference` to the code object wrapped by *gen*.
51 This function always succeeds.
52
53
54 Asynchronous Generator Objects
55 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56
57 .. seealso::
58 :pep:`525`
59
60 .. c:var:: PyTypeObject PyAsyncGen_Type
61
62 The type object corresponding to asynchronous generator objects. This is
63 available as :class:`types.AsyncGeneratorType` in the Python layer.
64
65 .. versionadded:: 3.6
66
67 .. c:function:: PyObject *PyAsyncGen_New(PyFrameObject *frame, PyObject *name, PyObject *qualname)
68
69 Create a new asynchronous generator wrapping *frame*, with ``__name__`` and
70 ``__qualname__`` set to *name* and *qualname*. *frame* is stolen by this
71 function and must not be ``NULL``.
72
73 On success, this function returns a :term:`strong reference` to the
74 new asynchronous generator. On failure, this function returns ``NULL``
75 with an exception set.
76
77 .. versionadded:: 3.6
78
79 .. c:function:: int PyAsyncGen_CheckExact(PyObject *op)
80
81 Return true if *op* is an asynchronous generator object, false otherwise.
82 This function always succeeds.
83
84 .. versionadded:: 3.6