functools.wraps behaviour

Ian Kelly ian.g.kelly at
Tue Sep 16 05:39:25 CEST 2014

On Mon, Sep 15, 2014 at 5:15 PM, ISE Development <isenntp at> wrote:
> The first two lines are as expected, using the name of the decorated
> function. However, the exception uses the name of the decorating wrapper
> function.
> Is this a bug in functools? Or is this a language feature? If so, is there a
> valid argument to change this behaviour?

I believe this is done in order to have useful stack traces. If it
said 'method' in the stack trace, it could mislead the person
debugging into thinking that method is actually raising the exception,
but here the exception is actually coming from wrapped, and method is
not even called.

More information about the Python-list mailing list