Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56644
| Date | 2013-10-11 15:36 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Skipping decorators in unit tests |
| References | <7w1u3so4lv.fsf@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.983.1381466200.18130.python-list@python.org> (permalink) |
On 11Oct2013 14:42, Ben Finney <ben+python@benfinney.id.au> wrote: > Cameron Simpson <cs@zip.com.au> writes: > > On 11Oct2013 02:55, Steven D'Aprano <steve+comp.lang.python@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. Sigh. Yes of course. It is no uglier than walking a frame stack etc. But is it reliable? Will it work on any decorated function? If so, fine, and I'd be happy to squirrel it away as a useful standard incantation for something. If not, then it's nasty only-mostly-reliable magic and I either want little to do with it, OR I want to know its specific limitations so I know when to use it and when not. -- Cameron Simpson <cs@zip.com.au> But pessimism IS realism! - D.L.Bahr
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 15:36 +1100
Re: Skipping decorators in unit tests Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 05:51 +0000
Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 17:40 +1100
csiph-web