Objetos de Função

Existem algumas funções específicas para as funções do Python.

PyFunctionObject

A estrutura C usada para funções.

PyTypeObject PyFunction_Type

Esta é uma instância de PyTypeObject e representa o tipo de função Python. Está exposto aos programadores Python como types.FunctionType.

int PyFunction_Check(PyObject *o)

Return true if o is a function object (has type PyFunction_Type). The parameter must not be NULL.

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

Retorna um novo objeto de função associado ao código objeto code. globals deve ser um dicionário com as variáveis globais acessíveis à função.

The function’s docstring, name and __module__ are retrieved from the code object, the argument defaults and closure are set to NULL.

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

Retorna o objeto de código associado ao objeto de função op.

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

Retorna o dicionário global associado ao objeto de função op.

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

Retorna o atributo __module__ do objeto de função op. Esta é normalmente uma string contendo o nome do módulo, mas pode ser configurada para qualquer outro objeto pelo código Python.

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

Return the argument default values of the function object op. This can be a tuple of arguments or NULL.

int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)

Set the argument default values for the function object op. defaults must be Py_None or a tuple.

Levanta SystemError e retorna -1 em falha.

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

Return the closure associated with the function object op. This can be NULL or a tuple of cell objects.

int PyFunction_SetClosure(PyObject *op, PyObject *closure)

Set the closure associated with the function object op. closure must be Py_None or a tuple of cell objects.

Levanta SystemError e retorna -1 em falha.