Skipping decorators in unit tests

Ben Finney ben+python at benfinney.id.au
Thu Oct 10 23:42:36 EDT 2013


Cameron Simpson <cs at zip.com.au> writes:

> 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.

What would you expect? The purpose of decorating functions is to do
magic to make it appear as though the original function isn't there any
more. Any technique to getting at that original function anyway is *of
course* going to look like black magic at the implementation level.

-- 
 \        “What if the Hokey Pokey IS what it's all about?” —anonymous |
  `\                                                                   |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list