函数对象

There are a few functions specific to Python functions.

type PyFunctionObject

The C structure used for functions.

PyTypeObject PyFunction_Type

This is an instance of PyTypeObject and represents the Python function type. It is exposed to Python programmers as types.FunctionType .

int PyFunction_Check ( PyObject * o )

返回 True 若 o is a function object (has type PyFunction_Type ). The parameter must not be NULL . This function always succeeds.

PyObject * PyFunction_New ( PyObject * code , PyObject * globals )
返回值:新引用。

Return a new function object associated with the code object code . globals must be a dictionary with the global variables accessible to the function.

The function’s docstring and name are retrieved from the code object. __module__ 检索自 globals . The argument defaults, annotations and closure are set to NULL . __qualname__ is set to the same value as the code object’s co_qualname 字段。

PyObject * PyFunction_NewWithQualName ( PyObject * code , PyObject * globals , PyObject * qualname )
返回值:新引用。

As PyFunction_New() , but also allows setting the function object’s __qualname__ 属性。 qualname should be a unicode object or NULL ;若 NULL __qualname__ attribute is set to the same value as the code object’s co_qualname 字段。

Added in version 3.3.