object.__dict__
and other places have their hidden methods set to things like this:
The object
class, since it's the base class of the class hierarchy. One can certainly infer that its underlying code is written to perform well.
In the CPython, the implementation of python is written in C and Python. The underlying code is written in C to satisfy the need for performance.
But then How is a call from a python script toward a function pointer that resides in some C compiled binary file managed and handled ??
Apparently a call to repr(b)
for example would follow the following logic :
__repr__
exists in b.__dict__
then try to call it.type(b).__dict__
the equivalent to A.__dict__
.A.__base__
, in our case that's the class object
. and since hasattr(object, '__repr__')==True
The lookup would finish by returning the bound method object.__repr__
, which is a slot wrapper that is an instance of the class wrapper_descriptor
.So it s pretty much a wrapper which uses the CPython's own API for builtins to save us the headache, and separate between the two languages' logic.
A Final Example Showing the same call twice :
>>> object.__repr__(b)
'<__main__.A object at 0x011EE5C8>'
>>> repr(b)
'<__main__.A object at 0x011EE5C8>'