在哪里可以查看内置 Python 方法 id() (Python 3.x) 的代码?

Where can I view the code for the built-in Python method id() (Python 3.x)?

在哪里可以查看内置 Python 方法 id() (Python 3.x) 的代码?

我一直在 Python 的 GitHub 页面上搜索它,但没有成功。我查看了与此相关的其他问题,但找不到具体方法 id()。

想看看这里是否有人知道该方法的代码在哪里。

与大多数内置名称一样,id() 函数在 Python/bltinmodule.c source file:

中定义
static PyObject *
builtin_id(PyModuleDef *self, PyObject *v)
/*[clinic end generated code: output=0aa640785f697f65 input=5a534136419631f4]*/
{
    return PyLong_FromVoidPtr(v);
}

这使用 Python C-API function PyLong_FromVoidPtr() to turn the address of the Python object referenced by the pointer v into a Python int object (using a system-specific cast to a C unsigned long or unsigned long long integer first)