[Python-ideas] parameter annotation semantics

Carl M. Johnson cmjohnson.mailinglist at gmail.com
Mon Apr 18 01:54:26 CEST 2011


On Sun, Apr 17, 2011 at 12:57 PM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Bruce Leban wrote:
>
>>    @memoize
>>    @log_me
>>    def c(foo:{memoize:memo_value(int)}, bar:{log_me:no_log,
>>    memoize:memo_value(tuple)}):
>>      pass
>>
>> but I think that's too verbose and therefore less likely to be adopted.
>
> Seems to me that *any* scheme for attaching multiple annotations
> is likely to lead to unreadably verbose function headers. Or even
> single annotations, for that matter.
>
> Back when the decorator syntax was being hammered out, one of the
> objections to putting the decorator on the same line as the function
> header was that it could lead to excessively long and hard-to-read
> headers. I think the whole open-slather annotation idea is asking
> for the same thing in spades.

That's a good point, but the above example *could* be rewritten:

foo_ans = {memoize: memo_value(int)}
bar_ans = {log_me: no_log, memoize:memo_value(tuple)}

@memoize
@log_me
def c(foo: foo_ans, bar:bar_ans):
        pass

But at that point you're probably better off just making a fancy
decorator that takes parameters instead of stuffing everything into an
annotation.



More information about the Python-ideas mailing list