What Defines a Callable Type in Python

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!

Alright, let’s start with the basics. A Python callable type is anything that you can call using (). This works because Python internally checks for the presence of __call__. If it’s there, the object is callable.

For example, regular functions are callable:

def foo():
    pass

print(callable(foo))  # True

But static and class methods? Not callable themselves!

class Demo:
    @staticmethod
    def static_method():
        pass

print(callable(Demo.static_method))  # False

That’s because static methods are just wrappers around callables, not callable objects themselves!

Good breakdown! But let’s go a little deeper.

A Python callable type doesn’t necessarily need to be a function—it can be an object with a __call__ method. If a class defines __call__, its instances become callable:

class CallableExample:
    def __call__(self):
        return 'I am callable!'

obj = CallableExample()
print(callable(obj))  # True

But what if a class doesn’t define __call__?

class NonCallableExample:
    pass

obj = NonCallableExample()
print(callable(obj))  # False

That’s the key difference—static and class methods don’t define __call__, so they’re not callable themselves, but the function inside them is!

Great points so far! But here’s something even more interesting—classes themselves are callable.

Why? Because the type class defines __call__.

class Example:
    pass

print(callable(Example))  # True ✅

This means when you do Example(), Python actually calls Example.__call__(), which is defined in type. That’s how instances are created! :rocket:

Similarly, built-in functions like max are callable:

print(callable(max))  # True ✅

So, in summary:

:heavy_check_mark: Functions & Methods → Callable (Because of __call__)

:heavy_check_mark: Instances → Callable if they define __call__

:heavy_check_mark: Classes → Callable (Because type has __call__)

:x: Static & Class Methods → Not callable (They wrap callables, but aren’t directly callable)

And that’s the complete picture of the Python callable type! :dart: