[Python-Dev] Proposed changes to PEP 343
Anders J. Munch
ajm at flonidan.dk
Fri Oct 7 15:23:47 CEST 2005
Nick Coghlan did a +1 job to write:
> 1. Amend the statement specification such that:
>
> with EXPR as VAR:
> BLOCK
>
> is translated as:
>
> abc = (EXPR).__with__()
> exc = (None, None, None)
> VAR = abc.__enter__()
> try:
> try:
> BLOCK
> except:
> exc = sys.exc_info()
> raise
> finally:
> abc.__exit__(*exc)
Note that __with__ and __enter__ could be combined into one with no
loss of functionality:
abc,VAR = (EXPR).__with__()
exc = (None, None, None)
try:
try:
BLOCK
except:
exc = sys.exc_info()
raise
finally:
abc.__exit__(*exc)
- Anders
More information about the Python-Dev
mailing list