[Python-Dev] Merging PEP 310 and PEP 340-redux?

Michael Hudson mwh at python.net
Tue May 10 09:16:25 CEST 2005


Guido van Rossum <gvanrossum at gmail.com> writes:

> Apologies if this has been discovered and rejected already; I've had
> to skip most of the discussions but this though won't leave my head...
>
> So PEP 310 proposes this:
>
>         with VAR = EXPR:
>             BLOCK
>
> translated to
>
>         VAR = EXPR\
> 	if hasattr(VAR, "__enter__"):
> 	    VAR.__enter__()
> 	try:
> 	    BLOCK
> 	finally:
>             VAR.__exit__()
>
> This equates VAR with the value of EXPR. It has a problem: what if
> inside BLOCK an assignment to VAR is made -- does this affect the
> finally clause or not? I think that the finally clause should use an
> internal variable that isn't affected by assignments to VAR.

Uh, if that's not clear from the PEP (and I haven't looked) it's an
oversight.  VAR is optional in PEP 310, after all.

Cheers,
mwh

-- 
  There's an aura of unholy black magic about CLISP.  It works, but
  I have no idea how it does it.  I suspect there's a goat involved
  somewhere.                     -- Johann Hibschman, comp.lang.scheme


More information about the Python-Dev mailing list