Oscar Benjamin wrote:

> A generator cannot guarantee that execution continues after a yield so
> any context manager used around a yield is dependent on __del__. I
> think a good rule of thumb is "don't yield from a with block".

Uh-oh, I am afraid I did this quite a few times. Most instances seem to be 
context managers though. Is something like

@contextmanager
def my_open(filename):
    if filename == "-":
        yield sys.stdin
    else:
        with open(filename) as f:
            yield f


OK?


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to