Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57933 > unrolled thread

stacked decorators and consolidating

Started byTim Chase <python.list@tim.thechases.com>
First post2013-10-29 11:54 -0500
Last post2013-10-29 11:54 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  stacked decorators and consolidating Tim Chase <python.list@tim.thechases.com> - 2013-10-29 11:54 -0500

#57933 — stacked decorators and consolidating

FromTim Chase <python.list@tim.thechases.com>
Date2013-10-29 11:54 -0500
Subjectstacked decorators and consolidating
Message-ID<mailman.1765.1383065569.18130.python-list@python.org>
I've got some decorators that work fine as such:

  @dec1(args1)
  @dec2(args2)
  @dec3(args3)
  def myfun(...):
    pass

However, I used that sequence quite a bit, so I figured I could do
something like

  dec_all = dec1(args1)(dec2(args2)(dec3(args3)))

to consolidate the whole mess down to

  @dec_all
  def myfun(...):
    pass

However, this yields different (test-breaking) results.  Messing
around, I found that if I write it as

  dec_all = lambda fn: dec1(args1)(dec2(args2)(dec3(args3)(fn)))

it works and passes all preexisting tests.

What am I missing that would cause this difference in behavior?

-tkc



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web