[Python-3000] Type annotations: annotating generators
Jim Jewett
jimjjewett at gmail.com
Fri May 19 21:27:33 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?
We have one:
def foo(a, b=2)
The signature of the function should describe it properly.
So the real question is how best to write "A callable with this
signature". I do not think the right answer is an inline recreation.
Compare to
from inspect import signature as sig
def button_pushed(button,
pressure=1,
alarm=False,
repeated=False, ...
# Give the signature a name, with ButtonFunc=sig(button_pushed) ? nah...
def foo(self, action:sig(button_pushed)): ...
And the decorator (if any) knows whether to enforce that the callback
have the right name, or to ignore even the count of arguments.
> Think about it: when's the last time you had a callback parameter that
> was called with keyword arguments?
It may be reasonable to require that the callback accept a keyword
such as 'color', rather than requiring it to take all possible GUI
parameters in a specific order.
-jJ
More information about the Python-3000
mailing list