python-2.1 function attributes

Duncan Booth duncan.booth at lineone.net
Fri Jan 26 04:54:58 EST 2001


Carel Fellinger <cfelling at iae.nl> wrote in <94pmsj$36d$1 at animus.fel.iae.nl>:

>Duncan Booth <duncan.booth at lineone.net> wrote:
>> Paul Prescod <paulp at ActiveState.com> wrote in 
>> <mailman.980396369.12407.python-list at python.org>:
>...
>> How about something along the following lines?
>
>> __attributes__= { 'attribute1' : 'val1', 'attribute2' : val2 }
>> def spam():
>>     """The doc string."""
>>     pass
>
>or even better(?) after the def but before spam making it visual clear
>that it belongs to spam's definition, but hasn't access to anything but
>the enclosing scope, like in:
>
>def { 'attribute1' : 'val1', 'attribute2' : val2 } spam():
>    """The doc string."""
>    pass
>
>this only works nice for litteral dicts, so bumber.

The advantage of my suggestion is that not only does it not require new 
syntax, but it doesn't put any limitations on how you create __attributes__. 
For example:
__attributes__ = ProjectDefaultAttributes()
__attributes__['unittest'] = '''Some unit test description'''
__attributes__['interface'] = SomeInterfaceStructure()
def spam(a, b):
    pass



More information about the Python-list mailing list