At 10:42 AM 5/11/2005 -0700, Guido van Rossum wrote: >[Phillip J. Eby] > > FYI, there are still use cases for clearing the exception state in an > > __exit__ method, that might justify allowing a true return from __exit__ to > > suppress the error. e.g.: >[...] > >Yes, but aren't those written clearer using an explicit try/except? >IMO anything that actually stops an exception from propagating outward >is worth an explicit try/except clause, so the reader knows what is >happening.
I thought the whole point of PEP 340 was to allow abstraction and reuse of patterns that currently use "try" blocks, including "except" as well as "finally". So, if you're only going to allow try/finally abstraction, wouldn't it make more sense to call it __finally__ instead of __exit__? That would make it clearer that this is purely for try/finally patterns, and not error handling patterns. As for whether they're written more clearly using an explicit try/except, I don't know. Couldn't you say exactly the same thing about explicit try/finally? For that matter, if you used function calls, doesn't it produce the same issue, e.g.: def retry(count,exc_type=Exception): def attempt(func): try: func() except exc_type: pass for i in range(count-1): yield attempt yield lambda f: f() for attempt in retry(3): attempt(somethingThatMightFail) Is this bad style too? _______________________________________________ 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