[Michael Hudson, after much thinking aloud] > Oh, I guess the point is that with a decorated generator you can yield > a value to be used as VAR, rather than just discarding the value as > here. Hmm.
Right. (I thought it was worth quoting this for the benefit of other who went down the same trail but didn't quite make it to this destination.) > If things were fiddled such that sys.exc_info() return non-Nones when > a finally clause is being executed because of an exception, we don't > really need this wart, do we? The problem is that sys.exc_info() almost always returns *something* -- it's usually the last exception that was *ever* caught, except in certain circumstances. Phillip wrote on the same issue: > I'm not sure the extra argument is a good idea; doesn't this introduce the > same sort of invisible control flow as swallowing exceptions? Also, since > the block controller can't actually change the control flow, I'm having a > hard time thinking of any actual use cases for this information. The 'oke' argument is so that the author of transactional() can decide what to do with a non-local goto: commit, rollback or hit the author over the head with a big stick. [Michael again] > Compare and contrast: > > @template > def redirected_stdout(out): > save_stdout = sys.stdout > sys.stdout = out > > yield None > > sys.stdout = save_stdout > > class redirected_stdout(object): > > def __init__(self, output): > self.output = output > > def __enter__(self): > self.save_stdout = sys.stdout > sys.stdout = self.output > > def __exit__(self): > sys.stdout = self.save_stdout > > The former is shorter and contains less (well, no) 'self.'s, but I > think I find the latter somewhat clearer. Tastes differ. I think the generator wins; more so when there's more state to remember. [Michael quoting Guido] > > The added complexity is caused by the need to separate VAR from EXPR > > so that a generator can be used. I personally like this separation; I > > actually like that the "anonymous block controller" is logically > > separate from the variable bound by the construct. > > Nevertheless, I think I actually like this argument! (Repeated for the benefit of others.) > > Straight up-or-down votes in the full senate are appreciated at this point. > > +1 for the PEP 340 variant. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com