Typing and Generics

typing.ParamSpec

Captures a callable's parameter specification so a wrapper can forward positional and keyword arguments while preserving its static call contract. Variance and bound semantics are not standardized for ParamSpec. Defaults arrived in 3.13.

Formal Syntax & Structure

python syntaxpython
typing.ParamSpec(name, *, bound=None, covariant=False, contravariant=False, infer_variance=False, default=NoDefault)

Parameters & Attributes

NameTypeDescription
namestrParameter specification name.
boundtype or NoneBound metadata; static semantics unspecified.
covariantboolVariance flag; static semantics unspecified.
contravariantboolVariance flag; static semantics unspecified.
infer_varianceboolVariance inference flag.
defaultobjectDefault parameter specification.

Return Value

ParamSpec

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

Working Example

Example Snippetpython
from typing import Callable, ParamSpec, TypeVar
P = ParamSpec('P')R = TypeVar('R')def wrap(fn: Callable[P, R]) -> Callable[P, R]:    def inner(*args: P.args, **kwargs: P.kwargs) -> R: return fn(*args, **kwargs)    return innerdef add(a: int, *, b: int) -> int: return a+bprint(wrap(add)(2,b=3))
Python Reference