Objetos función¶
Hay algunas funciones específicas para las funciones de Python.
-
type PyFunctionObject¶
La estructura C utilizada para las funciones.
-
PyTypeObject PyFunction_Type¶
Esta es una instancia de
PyTypeObjecty representa el tipo función de Python. Está expuesto a los programadores de Python comotypes.FunctionType.
-
int PyFunction_Check(PyObject *o)¶
Retorna verdadero si o es un objeto función (tiene tipo
PyFunction_Type). El parámetro no debe serNULL. Esta función siempre finaliza con éxito.
-
PyObject *PyFunction_New(PyObject *code, PyObject *globals)¶
- Return value: New reference.
Retorna un nuevo objeto función asociado con el objeto código code. globals debe ser un diccionario con las variables globales accesibles para la función.
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 toNULL.__qualname__is set to the same value as the 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 as the code object’sco_qualnamefield.Nuevo en la versión 3.3.
-
PyObject *PyFunction_GetCode(PyObject *op)¶
- Return value: Borrowed reference.
Retorna el objeto código asociado con el objeto función op.
-
PyObject *PyFunction_GetGlobals(PyObject *op)¶
- Return value: Borrowed reference.
Retorna el diccionario global asociado con el objeto función op.
-
PyObject *PyFunction_GetModule(PyObject *op)¶
- Return value: Borrowed reference.
Return a borrowed reference to the
__module__attribute of the function object op. It can be NULL.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.
Retorna los valores predeterminados del argumento del objeto función op. Esto puede ser una tupla de argumentos o
NULL.
-
int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)¶
Establece los valores predeterminados del argumento para el objeto función op. defaults deben ser
Py_Noneo una tupla.Lanza
SystemErrory retorna-1en caso de error.
-
PyObject *PyFunction_GetClosure(PyObject *op)¶
- Return value: Borrowed reference.
Retorna el cierre asociado con el objeto función op. Esto puede ser
NULLo una tupla de objetos celda.
-
int PyFunction_SetClosure(PyObject *op, PyObject *closure)¶
Establece el cierre asociado con el objeto función op. cierre debe ser
Py_Noneo una tupla de objetos celda.Lanza
SystemErrory retorna-1en caso de error.
-
PyObject *PyFunction_GetAnnotations(PyObject *op)¶
- Return value: Borrowed reference.
Retorna las anotaciones del objeto función op. Este puede ser un diccionario mutable o
NULL.
-
int PyFunction_SetAnnotations(PyObject *op, PyObject *annotations)¶
Establece las anotaciones para el objeto función op. annotations debe ser un diccionario o
Py_None.Lanza
SystemErrory retorna-1en caso de error.