Package logilab :: Package common :: Module decorators
[frames] | no frames]

Module decorators

source code

A few useful function/method decorators.

Classes
  wproperty
Simple descriptor expecting to take a modifier function as first argument and looking for a _<function name> to retrieve the attribute.
  classproperty
this is a simple property-like class but for class attributes.
  iclassmethod
Descriptor for method which should be available as class method if called on the class or instance method if called on an instance.
Functions
 
cached(callableobj, keyarg=None)
Simple decorator to cache result of method call.
source code
 
clear_cache(obj, funcname)
Function to clear a cache handled by the cached decorator.
source code
 
copy_cache(obj, funcname, cacheobj)
Copy cache for <funcname> from cacheobj to obj.
source code
 
timed(f) source code
 
locked(acquire, release)
Decorator taking two methods to acquire/release a lock as argument, returning a decorator function which will call the inner method after having called acquire(self) et will call release(self) afterwards.
source code
 
monkeypatch(klass, methodname=None)
Decorator extending class with the decorated function >>> class A: ...
source code
Function Details

monkeypatch(klass, methodname=None)

source code 
Decorator extending class with the decorated function
>>> class A:
...     pass
>>> @monkeypatch(A)
... def meth(self):
...     return 12
...
>>> a = A()
>>> a.meth()
12
>>> @monkeypatch(A, 'foo')
... def meth(self):
...     return 12
...
>>> a.foo()
12