ruff/crates/ty_python_semantic/resources/mdtest/annotations/starred.md
2025-05-03 19:49:15 +02:00

504 B

Starred expression annotations

[environment]
python-version = "3.11"

Type annotations for *args can be starred expressions themselves:

from typing_extensions import TypeVarTuple

Ts = TypeVarTuple("Ts")

def append_int(*args: *Ts) -> tuple[*Ts, int]:
    # TODO: tuple[*Ts]
    reveal_type(args)  # revealed: tuple

    return (*args, 1)

# TODO should be tuple[Literal[True], Literal["a"], int]
reveal_type(append_int(True, "a"))  # revealed: @Todo(full tuple[...] support)