Function metadata (like Java annotations) in Python

oripel oripel at
Sun Sep 10 04:13:28 CEST 2006


I'm trying to attach some attributes to functions and methods, similar
to Java annotations and .NET attributes.
I also want to use a convenient decorator for it, something along the
lines of

@attr(name="xander", age=10)
def foo():

Assigning attributes to the function will work, as will assigning keys
and values to a dictionary in an attribute. But if there are more
decorators in the way, this could fail:

def foo():

Given 'foo' now, how do I find the attributes?

Assigning to a global attribute registry (some interpreter-global
dictionary), although less desirable, might have been acceptable, but
then how do I identify the function after it's been wrapped in more

Also, it may be nice to have the following work as well:

def foo():

Any thoughts? Am I rehashing something old that my search skills didn't


More information about the Python-list mailing list