最近、Python で何かが頭をよぎりました: x = y(z)
is equal to x = y.__call__(z)
. ただし、テストはその仮定を無効にするように見え、Python のインタープリターがクラッシュする原因にもなります。
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)
2 番目を実行すると、 ret(1, 2, 3)
Python がクラッシュし、コマンド プロンプト ( image ) に戻ります。
ret = ret.__call__
ラインが実行されるとき、バックグラウンドで何が起こっていますか?- Python が最後の行で動作を停止するのはなぜですか? また、バグとして報告する必要がありますか?
役に立たないリファレンス: Python 関数とその__call__
属性