Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread Paddy
oripel wrote: Hi, 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

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks bearophile, I prefer not to use docstrings for metadata. 1. Not interfering with the other accepted docstring uses may be difficult (doctests, epydoc) 2. It's impractical for attributes generated by code: @attr(reference_profile_stats=pstats.Stats(foo.profile)) def foo(): ...

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks! Now I see it's accepted to assume nice decorators that update __dict__. At least until __decorates__ or something similar is added... fumanchu wrote: oripel wrote: I'm trying to attach some attributes to functions and methods, similar to Java annotations and .NET attributes. ...

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks Paddy - you're showing normal use of function attributes. They're still hidden when wrapped by an uncooperative decorator. Paddy wrote: oripel wrote: Hi, I'm trying to attach some attributes to functions and methods, similar to Java annotations and .NET attributes. I also want

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread George Sakkis
oripel wrote: Thanks Paddy - you're showing normal use of function attributes. They're still hidden when wrapped by an uncooperative decorator. The decorator module may be helpful in defining cooperative decorators: http://www.phyast.pitt.edu/~micheles/python/documentation.html George --

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks, In Python 2.5 there are also functools.wraps and functools.update_wrapper: http://docs.python.org/dev/whatsnew/pep-309.html George Sakkis wrote: oripel wrote: Thanks Paddy - you're showing normal use of function attributes. They're still hidden when wrapped by an uncooperative

Function metadata (like Java annotations) in Python

2006-09-09 Thread oripel
Hi, 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

Re: Function metadata (like Java annotations) in Python

2006-09-09 Thread bearophileHUGS
oripel: Maybe this is a silly suggestion, the docstring is already overloaded, but it may be used for this too: def foo(): ... ... @ATTR name=Xander @ATTR age=10 @ATTR hobby=knitting ... (Or somethins similar without the @). Later you can retrive the attributes

Re: Function metadata (like Java annotations) in Python

2006-09-09 Thread fumanchu
oripel wrote: I'm trying to attach some attributes to functions and methods, similar to Java annotations and .NET attributes. ... 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,