What is the definition of a Python callable type?
Background: I am trying to understand why static and class methods are not callable while being descriptors, whereas ordinary methods of a class (i.e., methods that are neither static nor class methods) and functions that are not attributes of classes are both descriptors and callable.
In Python, what exactly defines a callable type? According to the Python Data Model:
Callable types are described as types to which the function call operation (e.g., ()
operator) can be applied.
Does this imply that the operator for the “function call operation” is ()
? And if so, is a callable type simply defined as any type whose instances the function call operator ()
can be applied to?
Further, the Python Expressions documentation states:
The primary must evaluate to a callable object (e.g., user-defined functions, built-in functions, methods of built-in objects, class objects, methods of class instances, and all objects having a
__call__()
method are callable).
Does this mean that a Python callable type may or may not have a __call__()
method? If a class explicitly defines a __call__()
method, does that guarantee it is a callable type? Conversely, if a class does not define a __call__()
method, can it still be considered callable?
Additionally, do “user-defined functions, built-in functions, methods of built-in objects, class objects, and methods of class instances” lack a __call__()
method? Or are they instances of callable types by virtue of their implementation? What are their specific types, respectively?
Thank you for clarifying!