Message109815
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. |
|
Date |
User |
Action |
Args |
2010-07-10 03:39:26 | jackdied | set | recipients:
+ jackdied, rhettinger, ncoghlan, michael.foord |
2010-07-10 03:39:26 | jackdied | set | messageid: <1278733166.04.0.0547493219723.issue9110@psf.upfronthosting.co.za> |
2010-07-10 03:39:24 | jackdied | link | issue9110 messages |
2010-07-10 03:39:24 | jackdied | create | |
|