Teks sumber — English
Terjemahan — Bahasa Indonesia
Function Objects
Obyek Fungsi
This is an instance of :c:type:`PyTypeObject` and represents the Python function type. It is exposed to Python programmers as ``types.FunctionType``.
Return true if *o* is a function object (has type :c:data:`PyFunction_Type`). The parameter must not be ``NULL``. This function always succeeds.
Return a new function object associated with the code object *code*. *globals* must be a dictionary with the global variables accessible to the function.
The function's docstring and name are retrieved from the code object. :attr:`~function.__module__` is retrieved from *globals*. The argument defaults, annotations and closure are set to ``NULL``. :attr:`~function.__qualname__` is set to the same value as the code object's :attr:`~codeobject.co_qualname` field.
As :c:func:`PyFunction_New`, but also allows setting the function object's :attr:`~function.__qualname__` attribute. *qualname* should be a unicode object or ``NULL``; if ``NULL``, the :attr:`!__qualname__` attribute is set to the same value as the code object's :attr:`~codeobject.co_qualname` field.
Return the code object associated with the function object *op*.
Return the globals dictionary associated with the function object *op*.
Return a :term:`borrowed reference` to the :attr:`~function.__module__` attribute of the :ref:`function object <user-defined-funcs>` *op*. It can be *NULL*.
This is normally a :class:`string <str>` containing the module name, but can be set to any other object by Python code.
Return the argument default values of the function object *op*. This can be a tuple of arguments or ``NULL``.
Set the argument default values for the function object *op*. *defaults* must be ``Py_None`` or a tuple.
Set the vectorcall field of a given function object *func*.
Return the keyword-only argument default values of the function object *op*. This can be a dictionary of arguments or ``NULL``.
Set the keyword-only argument default values of the function object *op*. *defaults* must be a dictionary of keyword-only arguments or ``Py_None``.
Return the closure associated with the function object *op*. This can be ``NULL`` or a tuple of cell objects.
Set the closure associated with the function object *op*. *closure* must be ``Py_None`` or a tuple of cell objects.
Return the annotations of the function object *op*. This can be a mutable dictionary or ``NULL``.
Set the annotations for the function object *op*. *annotations* must be a dictionary or ``Py_None``.
If *event* is ``PyFunction_EVENT_CREATE``, then the callback is invoked after *func* has been fully initialized. Otherwise, the callback is invoked before the modification to *func* takes place, so the prior state of *func* can be inspected. The runtime is permitted to optimize away the creation of function objects when possible. In such cases no event will be emitted. Although this creates the possibility of an observable difference of runtime behavior depending on optimization decisions, it does not change the semantics of the Python code being executed.
If *event* is ``PyFunction_EVENT_DESTROY``, taking a reference in the callback to the about-to-be-destroyed function will resurrect it, preventing it from being freed at this time. When the resurrected object is destroyed later, any watcher callbacks active at that time will be called again.
object
objek