Ray.Allen <ysj....@gmail.com> added the comment:

Agreed with nick's idea, the implicitly recreation of the context managers 
would confuse users.

How about removing the "generator must yield exactly one value" restriction of 
@contextlib.contextmanage? Then if I want a generator to be used as a common 
context manager, I can make it yield exactly one value, else further if I want 
the resulting context manager can be used as a decorator, (reusable), I can put 
the generator code in a "while True" loop and add a "yield" at the end of loop 
body, like this:

@contextmanager
def func():
    while True:
        print('begin func')
        yield
        print('end func')
        yield

:)

----------
nosy: +ysj.ray

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

Reply via email to