[Nick Coghlan (replying to Phillip)] > Do you mean translating this: > > with EXPR1 as VAR1: > BLOCK1 > > To something along the lines of: > > the_stmt = EXPR1 > stmt_enter = getattr(the_stmt, "__enter__", None) > stmt_exit = getattr(the_stmt, "__exit__", None) > > if stmt_enter is None: > VAR1 = the_stmt > else: > VAR1 = stmt_enter() > > if stmt_exit is None: > BLOCK1 > else: > exc = (None, None, None) > try: > try: > BLOCK1 > except: > exc = sys.exc_info() > raise > finally: > stmt_exit(*exc) -1. The compiler must generate both code paths but one is wasted. I know this is not a very strong argument, but my gut tells me this generalization of the with-statement is wrong, so I'll stick to it regardless of the strength of the argument. The real reason will come to me. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
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