Function 对象¶
有一些特定于 Python 函数的函数。
- 
type PyFunctionObject¶
- 用于函数的 C 结构体。 
- 
PyTypeObject PyFunction_Type¶
- 这是一个 - PyTypeObject实例并表示 Python 函数类型。 它作为- types.FunctionType向 Python 程序员公开。
- 
int PyFunction_Check(PyObject *o)¶
- 如果 o 是一个函数对象 (类型为 - PyFunction_Type) 则返回真值。 形参必须不为- NULL。 此函数总是会成功执行。
- 
PyObject *PyFunction_New(PyObject *code, PyObject *globals)¶
- 返回值:新的引用。返回与代码对象 code 关联的新函数对象。 globals 必须是一个字典,该函数可以访问全局变量。 The function's docstring and name are retrieved from the code object. __module__ is retrieved from globals. The argument defaults, annotations and closure are set to NULL. __qualname__ is set to the same value as the code object'sco_qualnamefield.
- 
PyObject *PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname)¶
- 返回值:新的引用。As PyFunction_New(), but also allows setting the function object's__qualname__attribute. qualname should be a unicode object orNULL; ifNULL, the__qualname__attribute is set to the same value as the code object'sco_qualnamefield.3.3 新版功能. 
- 
PyObject *PyFunction_GetModule(PyObject *op)¶
- 返回值:借入的引用。向函数对象 op 的 __module__ 属性返回一个 borrowed reference。 该值可以为 NULL。 这通常为一个包含模块名称的字符串,但可以通过 Python 代码设为任何其他对象。 
- 
int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)¶
- 为函数对象 op 设置参数默认值。 defaults 必须为 - Py_None或一个元组。- 失败时引发 - SystemError异常并返回- -1。
- 
int PyFunction_SetClosure(PyObject *op, PyObject *closure)¶
- 设置关联到函数对象 op 的闭包。 closure 必须为 - Py_None或 cell 对象的元组。- 失败时引发 - SystemError异常并返回- -1。
- 
int PyFunction_SetAnnotations(PyObject *op, PyObject *annotations)¶
- 设置函数对象 op 的标注。 annotations 必须为一个字典或 - Py_None。- 失败时引发 - SystemError异常并返回- -1。