Decorators not worth the effort

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Sep 17 10:20:43 EDT 2012



----- Original Message -----
> Jean-Michel Pichavant wrote:
[snip]
> One minor note, the style of decorator you are using loses the
> docstring
> (at least) of the original function. I would add the
> @functools.wraps(func)
> decorator inside your decorator.

Is there a way to not loose the function signature as well ?

help (t.api.spuAgc)
> spuAgc(self, iterations, backoffTarget, step) method of ...



But once decorated with this:

def stdApi(func):
	@functools.wraps(func)
	def inner(self, *args, **kwargs):
		rsp = func(self, *args, **kwargs)
		result = TncCmnResult()
		result.returnCode = self._getReturnCode(rsp)
		return result
	return inner

help (t.api.spuAgc)
> t.api.spuAgc(self, *args, **kwargs) method of ....

Quite annoying :-/

JM



More information about the Python-list mailing list