Author jackdied
Recipients jackdied, michael.foord, ncoghlan, rhettinger
Date 2010-07-10.03:39:23
SpamBayes Score 0.000439397
Marked as misclassified No
Message-id <1278733166.04.0.0547493219723.issue9110@psf.upfronthosting.co.za>
In-reply-to
Content
Raymond,

Short version: This isn't theoretical because I use context managers and function decorators interchangeably and constantly.

Long Version: Function decorators and context managers have very similar use cases.  They both go something like:
  1) add optional extra state
  2) execute the original function (decorator) or block (context manager)
  3) add optional extra exception handling or do something special based on the extra state.

Frood's mock library does this in a very sane way.  ex/
@mock.patch(sys, 'stdio', someStringIOInstance)
def test_blah(self): pass

# this test uses context instead of decorators
def test_blaise(self):
  # test setup here
  with @mock.patch(sys, 'stdin', someStringIOInstance):
    dummy = 'something particular to this setup'
  # more tests here

So the use isn't theoretical [at a minimum he's doing it and I'm doing it], now we're just talking about what is the most obvious interface.
History
Date User Action Args
2010-07-10 03:39:26jackdiedsetrecipients: + jackdied, rhettinger, ncoghlan, michael.foord
2010-07-10 03:39:26jackdiedsetmessageid: <1278733166.04.0.0547493219723.issue9110@psf.upfronthosting.co.za>
2010-07-10 03:39:24jackdiedlinkissue9110 messages
2010-07-10 03:39:24jackdiedcreate