[IPython-dev] 'Unwrapping' decorated functions in IPython

Thomas Kluyver takowl at gmail.com
Fri Jul 15 09:35:44 EDT 2011


On 15 July 2011 14:11, Michele Simionato <michele.simionato at gmail.com>wrote:

> Are you sure Python 3.2 behavior is a design decision and not just an
> artifact (perhaps unwanted) of the current implementation?
>

No, not at all, it's just what I found happens when I try it. Looking at the
code for functools, I'm not even sure quite how it happens.

I agree that in many ways it makes more sense to have __wrapped__ look a
single layer down. In most code, you can just use a while loop to unwrap to
the bottom layer. But obviously people can call obj?? on any random Python
object, so we need to be a bit careful about what we assume.

Would it make sense to have an attribute called something like
_base_wrapped? Then in IPython, we could do:

obj = getattr(obj, "_base_wrapped", getattr(obj, "__wrapped__", obj))

Thanks,
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20110715/6d0fcef5/attachment.html>


More information about the IPython-dev mailing list