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 de
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
--
ht
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 a
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.
> >
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():
...
Regard
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
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 wa
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
a
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