Home | History | Annotate | Download | only in cpython
      1 from cpython.ref cimport PyObject
      2 
      3 cdef extern from "Python.h":
      4 
      5     ############################################################################
      6     # 7.5.3 Function Objects
      7     ############################################################################
      8     # There are a few functions specific to Python functions.
      9 
     10     # PyFunctionObject
     11     #
     12     # The C structure used for functions.
     13 
     14     # PyTypeObject PyFunction_Type
     15     #
     16     # This is an instance of PyTypeObject and represents the Python
     17     # function type. It is exposed to Python programmers as
     18     # types.FunctionType.
     19 
     20     bint PyFunction_Check(object o)
     21     # Return true if o is a function object (has type
     22     # PyFunction_Type). The parameter must not be NULL.
     23 
     24     object PyFunction_New(object code, object globals)
     25     # Return value: New reference.
     26     # Return a new function object associated with the code object
     27     # code. globals must be a dictionary with the global variables
     28     # accessible to the function.
     29     # The function's docstring, name and __module__ are retrieved from
     30     # the code object, the argument defaults and closure are set to
     31     # NULL.
     32 
     33     PyObject* PyFunction_GetCode(object op) except? NULL
     34     # Return value: Borrowed reference.
     35     # Return the code object associated with the function object op.
     36 
     37     PyObject* PyFunction_GetGlobals(object op) except? NULL
     38     # Return value: Borrowed reference.
     39     # Return the globals dictionary associated with the function object op.
     40 
     41     PyObject* PyFunction_GetModule(object op) except? NULL
     42     # Return value: Borrowed reference.
     43     # Return the __module__ attribute of the function object op. This
     44     # is normally a string containing the module name, but can be set
     45     # to any other object by Python code.
     46 
     47     PyObject* PyFunction_GetDefaults(object op) except? NULL
     48     # Return value: Borrowed reference.
     49     # Return the argument default values of the function object
     50     # op. This can be a tuple of arguments or NULL.
     51 
     52     int PyFunction_SetDefaults(object op, object defaults) except -1
     53     # Set the argument default values for the function object
     54     # op. defaults must be Py_None or a tuple.
     55     # Raises SystemError and returns -1 on failure.
     56 
     57     PyObject* PyFunction_GetClosure(object op) except? NULL
     58     # Return value: Borrowed reference.
     59     # Return the closure associated with the function object op. This
     60     # can be NULL or a tuple of cell objects.
     61 
     62     int PyFunction_SetClosure(object op, object closure) except -1
     63     # Set the closure associated with the function object op. closure
     64     # must be Py_None or a tuple of cell objects.
     65     # Raises SystemError and returns -1 on failure.
     66