Question presented to candidate:
"A normal TypeVar stands for one type. How would you type a function like call_soon(callback, *args) so the checker verifies that args match the callback's parameters, or an Array class whose type includes its shape, like Array[float, Height, Width]? What are TypeVarTuple and Unpack?"
What a strong answer should cover:
TypeVarTuple(PEP 646, Python 3.11) is a placeholder for any number of types, in order; it is always used unpacked, as*Tsor the equivalentUnpack[Ts]- Variadic generic classes:
class Array(Generic[DType, *Shape])letsArray[float, Height, Width]carry a shape; the motivating use is array shapes in NumPy-style libraries - Typed
*args:def f(*args: *Ts) -> tuple[*Ts]keeps each argument type;Callable[[*Ts], R]with*args: *Tsties a callback to its arguments (how typeshed typesasynciocall_soon) - Combining with
TypeVarfor prefix/suffix (tuple[T, *Ts]), and unpacking concrete tuple types (*tuple[int, ...]) - Limits: only one TypeVarTuple per parameter list,
*Tsonly on*args, no keyword arguments (useParamSpecfor that), the runtime checks none of it; 3.12 syntaxclass Array[DType, *Shape], 3.13 defaults
Code / implementation expected: Optional β a typed *args function or a callback scheduler using Callable[[*Ts], R], with what the checker infers.