python/cpython · error · TypeError

a callable object was expected by {method}(), got {callback!

Error message

a callable object was expected by {method}(), got {callback!r}

What it means

Error "a callable object was expected by {method}(), got {callback!r}" thrown in python/cpython.

Source

Thrown at Lib/asyncio/base_events.py:848

        Any positional arguments after the callback will be passed to
        the callback when it is called.
        """
        self._check_closed()
        if self._debug:
            self._check_thread()
            self._check_callback(callback, 'call_soon')
        handle = self._call_soon(callback, args, context)
        if handle._source_traceback:
            del handle._source_traceback[-1]
        return handle

    def _check_callback(self, callback, method):
        if (coroutines.iscoroutine(callback) or
                inspect.iscoroutinefunction(callback)):
            raise TypeError(
                f"coroutines cannot be used with {method}()")
        if not callable(callback):
            raise TypeError(
                f'a callable object was expected by {method}(), '
                f'got {callback!r}')

    def _call_soon(self, callback, args, context):
        handle = events.Handle(callback, args, self, context)
        if handle._source_traceback:
            del handle._source_traceback[-1]
        self._ready.append(handle)
        return handle

    def _check_thread(self):
        """Check that the current thread is the thread running the event loop.

        Non-thread-safe methods of this class make this assumption and will
        likely behave incorrectly when the assumption is violated.

        Should only be called when (self._debug == True).  The caller is
        responsible for checking this condition for performance reasons.

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Pass a callable object (function, method, functools.partial) as the callback; verify the argument is not None or a non-callable value.

When it happens

Trigger: Raised when a non-callable object is scheduled as a callback on the event loop.

Common situations: See trigger scenarios.


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/ec03a71ace43c95a. Report an issue: GitHub.