[Python-3000] signature annotation in the function signature or a separate line (original) (raw)
Samuele Pedroni pedronis at strakt.com
Sat Aug 19 12:54:19 CEST 2006
- Previous message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Next message: [Python-3000] signature annotation in the function signature or a separate line
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum wrote:
But maybe I'm misremembering the discussion, maybe decorators make it very difficult to visually scan for function definitions, and maybe people want all that garbage in their function signature.
They don't want it, but if they're forced to have it occasionally they'll cope. I still think you're way overestimating the importance of this use case.
Given that the meaning of annotations is meant not be predefined, given that people are comining with arbitrarely verbose examples thereof, given the precedent of type inferenced languages that use a separate line for optional type information I think devising a way to have the annotation on a different line with a decorator like introduction instead of mixed with the function head would be saner:
One possibility would be to have a syntax for signature expressions and then allow them as decorators with the obvious effect of attaching themself:
@sig int,int -> int def f(a,b): return a+b
or with argument optional argument names:
@sig a: int,b: int -> int def f(a,b): return a+b
sig expressions (possibly with parens) would be first class and be able to appear anywhere an expression is allowed, they would produce an object embedding the signature information.
So both of these would be possible:
@typecheck @sig int,int -> int def f(a,b): return a+b
@typecheck(sig int,int -> int) def f(a,b): return a+b
For example having first-class signatures would help express nicely reflective queries on overloaded/generic functions, etc...
regards.
- Previous message: [Python-3000] Function annotations considered obfuscatory (Re: Conventions for annotation consumers)
- Next message: [Python-3000] signature annotation in the function signature or a separate line
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]