Niko Matsakis wrote: >> >> txn = new_transaction() >> try: >> txn.begin() >> rtn = do_work() >> finally: >> if exception_occurred(): >> txn.abort() >> else: >> txn.commit() >> return rtn >> > > Couldn't you just do: > > txn = new_transaction () > try: > complete = 0 > txn.begin () > rtn = do_work () > complete = 1 > finally: > if not complete: txn.abort () > else: txn.commit () > > and then not need new builtins or anything fancy?
That would work, though it's less readable. If I were looking over code like that written by someone else, I'd have verify that the "complete" variable is handled correctly in all cases. (As Martin noted, your code already has a bug.) The nice try/except/else idiom we have today, with a bare except and bare raise, is much easier to verify. Shane _______________________________________________ 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