I'm curious how repr
works. It can't be exactly
def repr_(x):
return x.__repr__()
since that does not work on classes, namely
repr_(int)
causes an error since int
's repr expects an int
object as the first argument. I know that I can customize a class's repr
by creating a metaclass with a desired __repr__
, but I want to know how does Python's built in repr
work? And how does it specifically handle the case of having a class passed into it.
Does it do something like a try catch where it first tries what my repr_
does and then looks up the MRO for other reprs? Or something else?