'Location of `object.__init__`

Where is object.__init__ located in the cpython repository? I searched for __init__ in Objects/object.c, but it gives no results.

It appears that all the immutable data types use object.__init__, so I would like to know the implementation of it.



Solution 1:[1]

Objects/object.c is where (most of) the object protocol is implemented, not where object is implemented.

object is implemented along with type in Objects/typeobject.c, and its __init__ method is object_init in that file.

(Note that the very similar-sounding PyObject_Init function is actually completely unrelated to object.__init__. PyObject_Init is a generic helper function that performs type pointer and refcount initialization for a newly-allocated object struct.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1