Nick Coghlan wrote: > Exception propagation is a different story. What do you want to propagate? All > exceptions from the body of the for loop? Or just those from the yield statement? > > Well, isn't factoring out exception processing part of what PEP 343 is for? > # We can even limit the propagated exceptions to those > # from the outside world and leave the rest alone > def main_generator(): > ... > gen = sub_generator() > for value in gen: > with throw_to(gen): > input = yield value > continue input A point I should have made here (but didn't, despite using it in a later example) is that the "with" versions don't allow the nested generator to suppress the exception. A small refinement to gen.throw() that makes the first argument optional (similar to the raise statement itself) would make it straightforward to allow the generator to suppress passed in exceptions: def main_generator(): ... gen = sub_generator() for value in gen: try: input = yield value except: gen.throw() # Default to sys.exc_info(), just like raise continue input Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4