Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created June 14, 2013 16:39
Show Gist options
  • Save thomasballinger/5783398 to your computer and use it in GitHub Desktop.
Save thomasballinger/5783398 to your computer and use it in GitHub Desktop.
Examining __call__ of function objects - it's just a "method-wrapper," an object that wraps what is internally a method. I'm guessing the __call__ method is dynamically created when we ask for it, and there must be a short-circuit where function objects actually can get called with ().
>>> def foo(): return 1
>>> foo
<function foo at 0x10c5af488>
>>> foo.__call__
<method-wrapper '__call__' of function object at 0x10c5af488>
>>> foo.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x10c562c50>
>>> foo.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x10c64c8d0>
>>> foo.__call__.__call__.__call__()
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment