[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/)
_______________________________________________
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

Reply via email to