How to peek inside a decorated function

Steven D'Aprano steve at pearwood.info
Sun Feb 15 12:39:32 CET 2009


Hrvoje Niksic wrote:

>> Is there any way to peek inside the decorated function rsay() to get
>> access to the undecorated function say()?
> 
> This works in Python 2.5.2:
> 
>>>> rsay.func_closure[0].cell_contents
> <function say at 0xb7e67224>

Thanks to everyone who responded.


The reason I ask is because I've just spent the weekend battling with
doctests of decorated functions, and discovering that without
functools.wraps() all my doctests weren't being called. I'm wondering
whether it would be a good idea for doctest to auto-detect tests in
closures.

This is not needed if you call wraps() appropriately, but you might not
always do that.



-- 
Steven




More information about the Python-list mailing list