[Python-Dev] A syntax for function attributes?

Michael Hudson mwh@python.net
Wed, 30 Jul 2003 17:26:44 +0100

Barry Warsaw <barry@python.org> writes:

> On Wed, 2003-07-30 at 11:38, Mark Nottingham wrote:
>> PEP 232 lists syntactic support for function attributions to be a 
>> possible future direction. I would very much like to use function 
>> attributes for associating metadata with functions and methods, but the 
>> lack of such syntactic support precludes their use, so I end up 
>> (ab)using __doc__.
>> Has there been much further consideration of this issue? I'm not too 
>> particular about the chosen syntax, I just need something that doesn't 
>> require qualification with the function name (which tends to reduce 
>> readability/typeability, in some cases drastically so).
>> I'm happy to write a PEP if that will help, but wanted to get a sense 
>> of what people's thinking was.
> Function attributes of course already exist.  They seem like they'd be
> really cool to use <wink>.

Hmm, that's a surprise, coming from you :-)

> But I agree.  I think we did well not introducing new syntax for Python
> 2.3 so we owe it to ourselves to break that bad habit. :)  
> I'd also like to see syntactic support for method annotations, hooking
> into descriptors.  I've been using a lot of properties in some recent
> code and while they are very very cool (and IMO improve Python in some
> important ways), they are still too tedious to use.  I think the method
> annotation idea would be an elegant addition.

Method annotations can be made to do function attributes:

def attrs(**kw):
    def _(func):
        for k in kw:
            setattr(func, k, kw[k])
        return func
    return _

def func() [attrs(a=1, b=42)]:

but I don't recall how they do properties (and let's not have the
"extended function syntax" thread again, please).


  Now this is what I don't get.  Nobody said absolutely anything
  bad about anything.  Yet it is always possible to just pull
  random flames out of ones ass.
         -- http://www.advogato.org/person/vicious/diary.html?start=60