Jack Diederich <jackd...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9110>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to