python/cpython · error · TypeError
Expected a list of types, an ellipsis, ParamSpec, or Concate
Error message
Expected a list of types, an ellipsis, ParamSpec, or Concatenate. Got {t_args} What it means
TypeError raised by collections.abc.CallableType.__new__ (via typing.Callable) when the first slot of the subscription is not a list/tuple of types, an ellipsis, a ParamSpec, or a Concatenate object. Callable insists its parameter position be one of those forms; a bare type, string, or arbitrary object there is rejected with the offending value echoed.
Source
Thrown at Lib/_collections_abc.py:479
This sets ``__args__`` to a tuple containing the flattened
``argtypes`` followed by ``resulttype``.
Example: ``Callable[[int, str], float]`` sets ``__args__`` to
``(int, str, float)``.
"""
__slots__ = ()
def __new__(cls, origin, args):
if not (isinstance(args, tuple) and len(args) == 2):
raise TypeError(
"Callable must be used as Callable[[arg, ...], result].")
t_args, t_result = args
if isinstance(t_args, (tuple, list)):
args = (*t_args, t_result)
elif not _is_param_expr(t_args):
raise TypeError(f"Expected a list of types, an ellipsis, "
f"ParamSpec, or Concatenate. Got {t_args}")
return super().__new__(cls, origin, args)
def __repr__(self):
if len(self.__args__) == 2 and _is_param_expr(self.__args__[0]):
return super().__repr__()
from annotationlib import type_repr
return (f'collections.abc.Callable'
f'[[{", ".join([type_repr(a) for a in self.__args__[:-1]])}], '
f'{type_repr(self.__args__[-1])}]')
def __reduce__(self):
args = self.__args__
if not (len(args) == 2 and _is_param_expr(args[0])):
args = list(args[:-1]), args[-1]
return _CallableGenericAlias, (Callable, args)
def __getitem__(self, item):View on GitHub (pinned to bc6749cc3b)
Solutions
- Wrap the parameter types in a list: Callable[[int], str] instead of Callable[int, str].
- Use Callable[..., R] for 'any arguments'.
- Use a ParamSpec (P = ParamSpec('P'); Callable[P, R]) for propagating signatures of decorators.
- Validate annotation shapes with typing.get_args() in test suites for code that generates annotations.
Example fix
# before Callback = typing.Callable[int, str] # TypeError: Expected a list of types, an ellipsis, ... # after Callback = typing.Callable[[int], str] AnyArgs = typing.Callable[..., str]
Defensive patterns
Strategy: validation
Validate before calling
import typing
def first_slot_ok(t_args) -> bool:
from typing import ParamSpec
from typing_extensions import Concatenate
return (
isinstance(t_args, (tuple, list))
or t_args is Ellipsis
or isinstance(t_args, (ParamSpec, Concatenate))
) Type guard
def is_param_expr(x) -> bool:
import typing
try:
from typing_extensions import Concatenate
except ImportError:
Concatenate = ()
P = typing.ParamSpec
return isinstance(x, (list, tuple, P, Concatenate)) or x is Ellipsis Try / catch
try:
Alias = typing.Callable[spec]
except TypeError as e:
if 'Expected a list of types' in str(e):
Alias = typing.Callable[[spec[0]], spec[1]] # repair: wrap params in a list
else:
raise Prevention
- Remember the bracket-in-bracket shape: Callable[[int, str], bool].
- Use mypy/pyright in CI to catch malformed Callable subscriptions statically.
- When building specs from data, always emit a list for the parameter slot.
When it happens
Trigger: typing.Callable[int, str] (bare type instead of [int]); typing.Callable['int', str] (forward-ref string in the wrong slot); programmatically passing None or a class where a list was intended; Callable[..., None] is fine but Callable[Ellipsis, None] misused via * unpacking can slip through as an invalid shape.
Common situations: Misremembering the Callable syntax (very common typing mistake); macro/codegen emitting a single type for parameters; annotations assembled from JSON/strings where the parameter list loses its list wrapper; mixing typing.Callable with collections.abc.Callable usage in runtime validation.
Related errors
- Callable must be used as Callable[[arg, ...], result].
- module 'collections.abc' has no attribute {attr!r}
- Node can't use cause without an exception.
- coroutine ignored GeneratorExit
- asynchronous generator ignored GeneratorExit
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/73c6f56d146b0328.
Report an issue: GitHub.