2

I was just thinking; so in Python, the () you use to call a function/class/etc... is really an operator like any other, specifically this one maps to the __call__() magic method.

Except... __call__ would then have it's own .__call__. But surely that can't be the case, eventually it has to bottom out somewhere.

Except it doesn't:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> int.__call__
<method-wrapper '__call__' of type object at 0x58DE7028>
>>> int.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F6F0>
>>> int.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F590>
>>> int.__call__.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F6B0>
>>> int.__call__.__call__.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F870>
>>> int.__call__.__call__.__call__.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F630>
>>> int.__call__.__call__.__call__.__call__.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x0300F5F0>
>>>

Obviously some interpreter magic is happening in the background, but what exactly is going on here?

Schilcote
  • 2,344
  • 1
  • 17
  • 35
  • All of them: `__call__ __name__ __class__ __ne__ __delattr__ __new__ __dir__ __objclass__ __doc__ __qualname__ __eq__ __reduce__ __format__ __reduce_ex__ __ge__ __repr__ __getattribute__ __self__ __gt__ __setattr__ __hash__ __sizeof__ __init__ __str__ __le__ __subclasshook__ __lt__ __text_signature__ ` – Kh40tiK Dec 01 '16 at 10:51
  • Because `0x58DE7028 != 0x0300F6F0 != 0x0300F590 != 0x0300F6B0 != 0x0300F870 != 0x0300F630 != 0x0300F5F0` . You asking `call` is a `call` why ? :D – dsgdfg Dec 01 '16 at 10:53

0 Answers0