Function Objects¶
There are a few functions specific to Python functions.
- typePyFunctionObject¶
The C structure used for functions.
- PyTypeObjectPyFunction_Type¶
This is an instance of
PyTypeObjectand represents the Python functiontype. It is exposed to Python programmers astypes.FunctionType.
- intPyFunction_Check(PyObject*o)¶
Return true ifo is a function object (has type
PyFunction_Type).The parameter must not beNULL. This function always succeeds.
- PyObject*PyFunction_New(PyObject*code,PyObject*globals)¶
- Return value: New reference.
Return a new function object associated with the code objectcode.globalsmust be a dictionary with the global variables accessible to the function.
The function’s docstring and name are retrieved from the code object.
__module__is retrieved fromglobals. The argument defaults, annotations and closure areset toNULL.__qualname__is set to the same value asthe code object’sco_qualnamefield.
- PyObject*PyFunction_NewWithQualName(PyObject*code,PyObject*globals,PyObject*qualname)¶
- Return value: New reference.
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 asthe code object’sco_qualnamefield.New in version 3.3.
- PyObject*PyFunction_GetCode(PyObject*op)¶
- Return value: Borrowed reference.
Return the code object associated with the function objectop.
- PyObject*PyFunction_GetGlobals(PyObject*op)¶
- Return value: Borrowed reference.
Return the globals dictionary associated with the function objectop.
- PyObject*PyFunction_GetModule(PyObject*op)¶
- Return value: Borrowed reference.
Return aborrowed reference to the
__module__attribute of thefunction objectop.It can beNULL.This is normally a
stringcontaining the module name,but can be set to any other object by Python code.
- PyObject*PyFunction_GetDefaults(PyObject*op)¶
- Return value: Borrowed reference.
Return the argument default values of the function objectop. This can be atuple of arguments or
NULL.
- intPyFunction_SetDefaults(PyObject*op,PyObject*defaults)¶
Set the argument default values for the function objectop.defaults must be
Py_Noneor a tuple.Raises
SystemErrorand returns-1on failure.
- PyObject*PyFunction_GetClosure(PyObject*op)¶
- Return value: Borrowed reference.
Return the closure associated with the function objectop. This can be
NULLor a tuple of cell objects.
- intPyFunction_SetClosure(PyObject*op,PyObject*closure)¶
Set the closure associated with the function objectop.closure must be
Py_Noneor a tuple of cell objects.Raises
SystemErrorand returns-1on failure.
- PyObject*PyFunction_GetAnnotations(PyObject*op)¶
- Return value: Borrowed reference.
Return the annotations of the function objectop. This can be amutable dictionary or
NULL.
- intPyFunction_SetAnnotations(PyObject*op,PyObject*annotations)¶
Set the annotations for the function objectop.annotationsmust be a dictionary or
Py_None.Raises
SystemErrorand returns-1on failure.