function.pxd 2.6 KB

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