功能对象

有一些特定于Python函数的函数.

PyFunctionObject
用于功能的C结构.
PyTypeObject PyFunction_Type

这是PyTypeObject并代表Python函数类型。它接触到Python程序员types.FunctionType.

int PyFunction_Check( PyObject  *o)
如果o返回true是一个函数对象(类型为PyFunction_Type)。参数不能是NULL.
PyObject * PyFunction_New( PyObject  *code,PyObject  *globals)
Return value: New reference.

返回与代码对象关联的新函数对象code. globals必须是一个字典,函数可以访问全局变量.

函数的docstring和name是从代码对象中检索的。__module__是从globals。参数defaults,annotations和closure areset NULL. __qualname__设置为与函数名相同的值.

PyObject* PyFunction_NewWithQualName( PyObject  *code,PyObject  *globals,PyObject  *qualname)
Return value: New reference.

作为PyFunction_New(),还允许设置函数对象的__qualname__属性。qualname应该是一个unicode对象或NULL;如果为NULL,则__qualname__属性设置为与其__name__属性相同的值

在3.3版本中新增.

PyObject * PyFunction_GetCode( PyObject  *op)
Return value: Borrowed reference.

返回与函数对象关联的代码对象op.

PyObject * PyFunction_GetGlobals( PyObject  *op)
Return value: Borrowed reference.

返回与函数对象关联的全局字典op.

PyObject * PyFunction_GetModule( PyObject  *op)
Return value: Borrowed reference.

返回__module__函数对象的op属性。这通常是包含模块名称的字符串,但可以通过Python代码设置为任何其他对象.

PyObject* PyFunction_GetDefaults( PyObject  *op)
Return value: Borrowed reference.

返回函数对象op的参数默认值。这可以是参数的元组或NULL.

int PyFunction_SetDefaults( PyObject  *op,PyObject  *defaults)
集函数对象的对应默认值op. defaults必须是Py_None或者元组

//添加SystemError并在失败时返回-1。

PyObject * PyFunction_GetClosure( PyObject  *op)
Return value: Borrowed reference.

返回与函数对象op关联的闭包。这可以是NULL或一个单元格的元组.

int PyFunction_SetClosure(的PyObject  *op,PyObject  *closure)
设置与函数对象关联的闭包op. closure一定是Py_None或者是细胞物的元组.

提高SystemError并返回-1失败时

PyObject * PyFunction_GetAnnotations( PyObject  *op)
Return value: Borrowed reference.

返回函数对象op的注释。这可以是amutable dictionary或NULL.

int PyFunction_SetAnnotations( PyObject  *op,PyObject  *annotations)
设置函数对象的注释op. annotations必须是字典或Py_None.

引发SystemError并在失败时返回-1

评论被关闭。