Skipping decorators in unit tests

Terry Reedy tjreedy at udel.edu
Fri Oct 11 04:25:41 EDT 2013


On 10/11/2013 4:17 AM, Terry Reedy wrote:
> On 10/10/2013 11:13 PM, Cameron Simpson wrote:
>> On 11Oct2013 02:55, Steven D'Aprano
>> <steve+comp.lang.python at pearwood.info> wrote:
>
>>> def undecorate(f):
>>>      """Return the undecorated inner function from function f."""
>>>      return f.func_closure[0].cell_contents
>>
>> Whereas this feels like black magic. Is this portable to any decorated
>> function? If so, I'd have hoped it was in the stdlib. If not: black
>> magic.
>>
>>> And in use:
>>>
>>> py> f(100)
>>> 201
>>> py> undecorate(f)(100)
>>> 200
>>
>> All lovely, provided you can convince me that undecorate() is robust.
>> (And if you can, I'll certainly be filing it away in my funcutils
>> module for later use.)
>
> It only works if the decorator returns a closure with the original
> function as the first member (of func_closure). Often true, but not at
> all a requirement.
>


-- 
Terry Jan Reedy




More information about the Python-list mailing list