Something crossed my mind recently in Python: x = y(z)
is equivalent to x = y.__call__(z)
. However, a test appears to invalidate that assumption and also leads to Python's interpreter to crash.
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def ret(*args):
... return args
...
>>> ret(1, 2, 3)
(1, 2, 3)
>>> for _ in range(1000000):
... ret = ret.__call__
...
>>> ret(1, 2, 3)
Running the second ret(1, 2, 3)
leads Python to crash and return to the command prompt (image).
- What is happening in the background when the line
ret = ret.__call__
executes? - Why does Python stop working on the last line, and should it be reported as a bug?
Useless Reference: Python functions and their __call__
attribute