How are python built-in functions are implemented? Some of them like issubclass are wrappers around object methods.
About id() Documentation says that:
For CPython, id(x) is the memory address where x is stored.
When talking about id(), other places in documentation do not say anything more!
So how has id() been implemented? I think it doesn't have to do with any methods of the object in Cpython API. Just to have them, I used dir(x):
foo = [1,2,3]
dir(foo)
>> ['__add__',
'__class__',
'__contains__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__gt__',
'__hash__',
'__iadd__',
'__imul__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__rmul__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__']
id, that function can be more byte code, but it can also be a C function. Search for "builtin_id` in github.com/python/cpython/blob/main/Python/bltinmodule.c and you'll see the C implementation ofid(some_object). That's the code being run. It takes the memory address ofsome_objectconverts it to a python integer (called "long" in the C codePyLong_FromVoidPtr(v)) and returns.idis nonsensical. If it's the same object, then it's the same object; if not, it's not. Allowing you to overloadidwould allow two independent objects to claim to be the same object, which is nuts (e.g. it would make it possible forif myobj is None:to returnTrue, even whenmyobjis a custom class, notNone;isis an identity test after all, andid(x) == id(y)is equivalent to testingx is y).