What exactly happens when a function is called in Python? Does the interpreter call a __call__
method of an object? Then, why does the behaviour of function stay the same when I replace its __call__
method?
(I am working with Python 3)
>>> def foo(): return 1
>>> foo()
1
>>> foo.__call__()
1
>>> foo.__call__ = lambda: 2
>>> foo.__call__()
2
>>> foo()
1
Thank you.