[Python-3000] Type annotations: annotating generators

Collin Winter collinw at gmail.com
Fri May 19 20:38:23 CEST 2006


On 5/19/06, Guido van Rossum <guido at python.org> wrote:
> I think it's overkill and still not enough. When I write "def foo(a,
> b=2): ..." all of the following call signatures are valid: foo(1),
> foo(a=1), foo(1, 2), foo(1, b=2), foo(a=1, b=2), foo(b=2, a=1). Do we
> really want a notation that lets us describe that?
>
> I would like to push back and *only* support fixed-number positional
> parameters and a return value for signature declarations.
>
> Think about it: when's the last time you had a callback parameter that
> was called with keyword arguments?
>
> Keyword arguments, varargs, etc. are nice when calling specific known
> functions/methods. But I'm not sure that they are all that interesting
> when coding higher-order functions.

I'll concede that callbacks aren't often invoked in the foo(4, 5, c=7)
style (so requiring certain parameter names is off the table), but
I'll in turn push back on varargs and varkw parameters.

I see these as being genuinely useful in higher-order functions,
especially functions that take a variable-length constructor (like
list, dict, etc). Since we're no longer using Function()'s keyword
arguments to make assertions about parameter names, we can eliminate
the ugliness of star() and double_star() by having *varargs and
**varkw parameters grab their types from keyword arguments. That is,

def foo(a: Sequence, b: Number, *varargs: Number, **varkw: Number)

would be approved by

Function(Sequence, Number, varargs=Number, varkw=Number)

The excess argument parameters would be the only ones addressable with
keyword arguments (vargs and kwargs or varargs and varkw, makes no
difference to me). These arguments would have to be passed as
keywords, thus making explicit your intention to use excess positional
and/or keyword arguments.

Collin Winter


More information about the Python-3000 mailing list