Signature-preserving decorators

Henrik Faber hfaber at invalid.net
Tue Dec 13 08:36:39 EST 2011


Hi group,

when decorating a method in Python3, by use of the
functools.update_wrapper function, it can be achieved that the docstring
and name of the original function is preseverved.

However, the prototype is lost: When looking into the Python help, I
have lots of entries that look like:

getfoo(*args, **kwargs) -> int

setbar(*args, **kwargs)

As you can imagine, this is really not very self-explanatory. I've seen
a solution which constructs a wrapper's wrapper function using
inspection and eval -- this looks really dirty to me, however. Then
there's the "decorator" external module -- but I'd like to do it with
on-board tools.

Is this possible in Python3 with too much of a hassle?

Best regards,
Joe




More information about the Python-list mailing list