[Python-Dev] Re: A syntax for function attributes?

Mark Nottingham mnot@mnot.net
Thu, 31 Jul 2003 14:55:51 -0700

On Thursday, July 31, 2003, at 05:06 AM, Michael Chermside wrote:
> I don't object to a syntax for function attributes... in fact, I've 
> seen no
> specific proposal to object to.

See PEP 232 [1], which lists several.

1. http://www.python.org/peps/pep-0232.html

> Only once we see how very useful this really is should we consider
> introducing special syntax for it, because the less special syntax
> that Python has, the better it is (if we keep functionality constant).

I find function attributes very useful as a way of associating metadata 
with functions and methods; this style of coding is gaining a lot of 
traction elsewhere (e.g., JSRs 175 [2] and 181 [3]  in the Java world).

2. http://www.jcp.org/en/jsr/detail?id=175
3. http://www.jcp.org/en/jsr/detail?id=181

I'll be happy to explain my use case if that would help.

> syntax... like PEP 310 where we prevent the race condition. And the
> third exception is cases where the proponants claim that the syntax
> change itself is what makes the difference -- for instance those
> who point to ruby's blocks as very useful while Python's lambda's
> have just a little bit too much typing. (Not that I agree, necessarily,
> but they're entitled to make their point.)

I think that's the boat we're in now; the overhead of writing precludes 
most people from using function attributes for metadata, because it 
places too much of a readability as well as type-ability barrier in the 
way; using __doc__ is the path of least resistance, until there is a 
special syntax.


def heres_my_function_name(args):
    heres_my_function_name.my_attribute = "Foo"

Without a special syntax, I think we'll see more and more abuses of 
__doc__, like

def heres_my_function_name(args):
    """my_attribute = "Foo" """