Decorators not worth the effort

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Sep 14 11:19:58 EDT 2012


On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote:

> Here's Steven example:
> 
> # Untested!
> def timeout(t=15):
>     # Decorator factory. Return a decorator to actually do the work. if
>     FPGA:
>         t *= 3
>     def decorator(func):
>         @functools.wraps(func)
>         def inner(self, timeout):
>             self.sendCmd("bootMe", timeout=t)
>         return inner
>     return decorator
> 
> I can assure you, that for some python users, it's is not easy to
> understand what it does, this function returning a function which
> returns another (wrapped) function. It requires some effort.

Oh I agree. So does learning to tie your shoe-laces, learning to cook, 
and learning to drive.

Learning to be a world-class chess master takes a lot of effort. Learning 
about decorators does not.


-- 
Steven



More information about the Python-list mailing list