Generator Objects

Generator objects are what Python uses to implement generator iterators. Theyare normally created by iterating over a function that yields values, ratherthan explicitly callingPyGen_New() orPyGen_NewWithQualName().

typePyGenObject

The C structure used for generator objects.

PyTypeObjectPyGen_Type

The type object corresponding to generator objects.

intPyGen_Check(PyObject*ob)

Return true ifob is a generator object;ob must not beNULL. Thisfunction always succeeds.

intPyGen_CheckExact(PyObject*ob)

Return true ifob’s type isPyGen_Type;ob must not beNULL. This function always succeeds.

PyObject*PyGen_New(PyFrameObject*frame)
Return value: New reference.

Create and return a new generator object based on theframe object.A reference toframe is stolen by this function. The argument must not beNULL.

PyObject*PyGen_NewWithQualName(PyFrameObject*frame,PyObject*name,PyObject*qualname)
Return value: New reference.

Create and return a new generator object based on theframe object,with__name__ and__qualname__ set toname andqualname.A reference toframe is stolen by this function. Theframe argumentmust not beNULL.

PyCodeObject*PyGen_GetCode(PyGenObject*gen)

Return a newstrong reference to the code object wrapped bygen.This function always succeeds.

Asynchronous Generator Objects

See also

PEP 525

PyTypeObjectPyAsyncGen_Type

The type object corresponding to asynchronous generator objects. This isavailable astypes.AsyncGeneratorType in the Python layer.

Added in version 3.6.

PyObject*PyAsyncGen_New(PyFrameObject*frame,PyObject*name,PyObject*qualname)

Create a new asynchronous generator wrappingframe, with__name__ and__qualname__ set toname andqualname.frame is stolen by thisfunction and must not beNULL.

On success, this function returns astrong reference to thenew asynchronous generator. On failure, this function returnsNULLwith an exception set.

Added in version 3.6.

intPyAsyncGen_CheckExact(PyObject*op)

Return true ifop is an asynchronous generator object, false otherwise.This function always succeeds.

Added in version 3.6.