Stéphane Wirtel | cbb6484 | 2019-05-17 11:55:34 +0200 | [diff] [blame] | 1 | .. highlight:: c |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 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 |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 10 | than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 11 | |
| 12 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 13 | .. c:type:: PyGenObject |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 14 | |
| 15 | The C structure used for generator objects. |
| 16 | |
| 17 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 18 | .. c:var:: PyTypeObject PyGen_Type |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 19 | |
Martin Panter | d21e0b5 | 2015-10-10 10:36:22 +0000 | [diff] [blame] | 20 | The type object corresponding to generator objects. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 21 | |
| 22 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 23 | .. c:function:: int PyGen_Check(PyObject *ob) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 24 | |
| 25 | Return true if *ob* is a generator object; *ob* must not be *NULL*. |
| 26 | |
| 27 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 28 | .. c:function:: int PyGen_CheckExact(PyObject *ob) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 29 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 30 | Return true if *ob*'s type is *PyGen_Type*; *ob* must not be *NULL*. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 31 | |
| 32 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 33 | .. c:function:: PyObject* PyGen_New(PyFrameObject *frame) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 34 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 35 | 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 Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 37 | *NULL*. |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 38 | |
| 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*. |