callable arrow syntax¶
basedpython adds an arrow form for callable types so function-typed annotations read naturally:
transpiles to:
on_done: Callable[[int, str], bool]
fetch: Callable[[], bytes]
curry: Callable[[int], Callable[[str], bool]]
syntax¶
->separates parameters from return type- form nests: right side can itself be callable, producing curried
Callable[[A], Callable[[B], C]] - bare positional types (
(int, str)) get implicit positional-only treatment when followed by named parameters
parameter forms¶
gradual (...)¶
a single bare ellipsis parameter list is the gradual "any arguments" callable:
→ Callable[..., int] (not Callable[[...], int]). it accepts any
argument list, and the reverse transpile maps Callable[..., R] back to
(...) -> R
bare positional¶
→ Callable[[int, str], bool]
named parameter¶
named parameters are non-denotable in Callable[...]; basedpython emits an equivalent shape behind the scenes
positional-only marker /¶
explicit / marks preceding params positional-only. implicit / is
inserted after the last bare positional when followed by a named
parameter
keyword-only marker *¶
bare * marks following params keyword-only
variadic *args¶
kwargs **kwargs¶
full form¶
scope¶
arrow form recognized only in syntactic type positions: parameter
annotations, return-type annotations, AnnAssign targets, type aliases,
and subscript slices that are themselves type contexts
(list[(int) -> int]). value-context (int) -> int remains a parse
error
nesting¶
callable nests inside callable, union, intersection, tuple, subscript:
polyfill¶
Callableimported fromtypingonce per module using denotable formProtocolimported fromtypingonce per module using non-denotable form