Function 對象?

有一些特定于 Python 函數的函數。

type PyFunctionObject?

用于函數的 C 結構體。

PyTypeObject PyFunction_Type?

這是一個(gè) PyTypeObject 實(shí)例并表示 Python 函數類(lèi)型。 它作為 types.FunctionType 向 Python 程序員公開(kāi)。

int PyFunction_Check(PyObject *o)?

如果 o 是一個(gè)函數對象 (類(lèi)型為 PyFunction_Type) 則返回真值。 形參必須不為 NULL。 此函數總是會(huì )成功執行。

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

返回與代碼對象 code 關(guān)聯(lián)的新函數對象。 globals 必須是一個(gè)字典,該函數可以訪(fǎng)問(wè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 to NULL. __qualname__ is set to the same value as the code object's co_qualname field.

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 or NULL; if NULL, the __qualname__ attribute is set to the same value as the code object's co_qualname field.

3.3 新版功能.

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

返回與函數對象 op 關(guān)聯(lián)的代碼對象。

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

返回與函數對象*op*相關(guān)聯(lián)的全局字典。

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

向函數對象 op__module__ 屬性返回一個(gè) borrowed reference。 該值可以為 NULL。

這通常為一個(gè)包含模塊名稱(chēng)的字符串,但可以通過(guò) Python 代碼設為任何其他對象。

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

返回函數對象 op 的參數默認值。 這可以是一個(gè)參數元組或 NULL。

int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)?

為函數對象 op 設置參數默認值。 defaults 必須為 Py_None 或一個(gè)元組。

失敗時(shí)引發(fā) SystemError 異常并返回 -1 。

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

返回關(guān)聯(lián)到函數對象 op 的閉包。 這可以是 NULL 或 cell 對象的元組。

int PyFunction_SetClosure(PyObject *op, PyObject *closure)?

設置關(guān)聯(lián)到函數對象 op 的閉包。 closure 必須為 Py_None 或 cell 對象的元組。

失敗時(shí)引發(fā) SystemError 異常并返回 -1 。

PyObject *PyFunction_GetAnnotations(PyObject *op)?
Return value: Borrowed reference.

返回函數對象 op 的標注。 這可以是一個(gè)可變字典或 NULL。

int PyFunction_SetAnnotations(PyObject *op, PyObject *annotations)?

設置函數對象 op 的標注。 annotations 必須為一個(gè)字典或 Py_None。

失敗時(shí)引發(fā) SystemError 異常并返回 -1 。