0

I used to think functions, classes, and methods as the only callables in Python, but recently learnt that instances can also be made callable. This left me wondering if I'm done with this list or are there more types of callables I'm yet to encounter.

Neo Anderson
  • 35
  • 1
  • 1
  • 7
  • 2
    Any object that has `__call__` defined is a callable – Cory Kramer Dec 07 '22 at 14:02
  • 1
    Also, everything you've mentioned is callable via `__call__`: `types.FunctionType.__call__`, `type.__call__`, `types.MethodType.__call__` all exist. – chepner Dec 07 '22 at 14:07
  • As far as I can tell, the type of all *those* callables is `wrapper_descriptor` (certainly a CPython implementation detail), which would make that the only *ur*-callable type. (All other types being callable because they define `__call__`, not because they are somehow special-cased to be callable.) – chepner Dec 07 '22 at 14:09
  • Oops: there is also `method-wrapper` (another CPython implementation detail, the type of e.g. `id.__call__`. Circularity ensues when you ask about `id.__call__.__call__`, `id.__call__.__call__.__call__`, etc. It's `__call__`s all the way down. – chepner Dec 07 '22 at 14:12

0 Answers0