Typing and Generics

typing.Concatenate

Combines leading positional parameter types with a ParamSpec (or ellipsis) inside Callable. Useful for wrappers that supply an extra argument. It does not modify a callable's signature at runtime.

Formal Syntax & Structure

python syntaxpython
typing.Concatenate[T1, ..., P]

Return Value

type expression

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import Callable, Concatenate, ParamSpec, TypeVar
P = ParamSpec('P')R = TypeVar('R')def bind(fn: Callable[Concatenate[str, P], R]) -> Callable[P,R]:    def inner(*args:P.args, **kwargs:P.kwargs) -> R: return fn('ID', *args, **kwargs)    return innerdef label(prefix: str, n: int) -> str: return f'{prefix}:{n}'print(bind(label)(7))
Python Reference