Peter Otten wrote:
I usually use decorator functions, but I think the following should work,
too:
class deco(object):
def __init__(self, func):
self._func = func
def __call__(self, *args):
print Decorator:, args
self._func(*args)
def __get__(self, *args):
On May 12, 8:54 am, Mikael Olofsson mik...@isy.liu.se wrote:
Peter Otten wrote:
I usually use decorator functions, but I think the following should work,
too:
class deco(object):
def __init__(self, func):
self._func = func
def __call__(self, *args):
print
Michele Simionato michele.simion...@gmail.com wrote:
On May 12, 8:54 am, Mikael Olofsson mik...@isy.liu.se wrote:
Peter Otten wrote:
I usually use decorator functions, but I think the following should
wor
k,
too:
class deco(object):
def __init__(self, func):
Michele Simionato wrote:
Still it turns something which is a function into an object and
you lose the docstring and the signature. pydoc will not be too
happy with this approach.
Duncan Booth wrote:
I don't know why Mikael wants to use a class rather than a function
but if he wants to save
On May 8, 5:33 pm, Mikael Olofsson mik...@isy.liu.se wrote:
class test_decorator(object):
... def __init__(self,func):
... self._func = func
... def __call__(self, *args):
... print 'Decorator:', args
... self._func(*args)
Or you could use the decorator
Peter Otten wrote:
You have to turn your decorator into a descriptor by providing a __get__()
method. A primitive example:
class test_decorator(object):
def __init__(self,func):
self._func = func
def __call__(self, *args):
print 'Decorator:', args
George Sakkis wrote:
Yes, just return an actual function from the decorator instead of a
callable object:
def test_decorator2(func):
def wrapper(*args):
print 'Decorator2:', args
func(*args)
return wrapper
class cls(object):
@test_decorator
def
Mikael Olofsson mik...@isy.liu.se wrote:
George Sakkis decorator function solution seems to work equally well
for
functions and methods. However, I prefer the cleaner encapsulation
given
by a class. Based on those observations, I think I will use the
following approach:
class
Duncan Booth wrote:
The __get__ method should be returning a new object, NOT modifying the
state of the decorator. As written it will break badly and unexpectedly
in a variety of situations:
[snip good examples of things going bad]
Ouch! So, does that mean that George's solution based on a
Mikael Olofsson wrote:
Duncan Booth wrote:
The __get__ method should be returning a new object, NOT modifying the
state of the decorator. As written it will break badly and unexpectedly
in a variety of situations:
[snip good examples of things going bad]
Ouch! So, does that mean that
On May 8, 11:33 am, Mikael Olofsson mik...@isy.liu.se wrote:
Hi all!
I have long tried to avoid decorators, but now I find myself in a
situation where I think they can help. I seem to be able to decorate
functions, but I fail miserably when trying to decorate methods. The
information I have
Mikael Olofsson wrote:
Hi all!
I have long tried to avoid decorators, but now I find myself in a
situation where I think they can help. I seem to be able to decorate
functions, but I fail miserably when trying to decorate methods. The
information I have been able to find on-line focuses on
Hi all!
I have long tried to avoid decorators, but now I find myself in a
situation where I think they can help. I seem to be able to decorate
functions, but I fail miserably when trying to decorate methods. The
information I have been able to find on-line focuses on decorating
functions,
Mikael Olofsson wrote:
Hi all!
I have long tried to avoid decorators, but now I find myself in a
situation where I think they can help. I seem to be able to decorate
functions, but I fail miserably when trying to decorate methods. The
information I have been able to find on-line focuses on
14 matches
Mail list logo