Parameters¶
Arguments gathers a function's leftover arguments when
there's no fixed, named prefix to keep separate from the open overflow.
Parameters extends it with exactly that prefix:
Parameters inheriting from Arguments the
ordinary way (see Class inheritance). pargs
holds whatever fixed, possibly zoned prefix a signature has, typed as
an Anonymous class itself when it needs its own
positional-only or ordinary zoning.
Parameters is for describing a signature whole — the case a
decorator's generic forwarding needs, where there's no way to declare
the fixed part as ordinary, separately named parameters up front,
because the wrapper doesn't know what they will be (see
Decorators). Parameters is usable as a bound the
same way dict or Functor are, and a plain nominal class's unzoned
field shape satisfies it as the simplest case.
A signature's full shape, open-ended content included, can be written
inline by extending Anonymous class's grammar with its two remaining
zones: a bare, unnamed type followed by ... for the variadic
positional tail, and _: type, ... for the variadic keyword one, after
the fixed prefix and its keyword-only zone respectively — the same
positional-before-keyword order every zone already follows:
c: int, /, a: int — the fixed, possibly zoned prefix:
Anonymous class, exactly as written there.
- int, ... — variadic positional: zero or more further int\ s,
after every fixed position — nothing fixed can follow it, since it
consumes every remaining positional slot. The trailing ... is the
same marker that opens a TypedDict shape
(TypedDict shapes in type position), here meaning
"and more of the type just written," not "anything."
- *, b: int — the keyword-only zone, Anonymous class again.
- _: int, ... — variadic keyword: zero or more further keyword
arguments, each int. _ marks the slot as nameless the same way
it already does for black-hole assignment
(Ordinary binding) — the key isn't fixed,
only the value's type is.
This is inline sugar for a direct Parameters instantiation:
_: type,
... — trigger this desugaring. / and a named keyword-only zone
don't: they stay inside the fixed prefix, an ordinary Anonymous class
shape in its own right, which is why pargs's own type can have a
/ in it without becoming another Parameters — a fixed, zoned but
non-variadic prefix needs no aggregation, only genuinely open-ended
content does. query's full type follows the same rule, with an empty
prefix, since path is already named separately:
What isn't ordinary about either class is how *** treats pargs,
vpargs, and kwargs specifically, on both the gathering and the
spreading side — Gather and Spread cover
each in turn.