[Python-Dev] 'With' context documentation draft (was Re: Terminology for PEP 343

Walter Dörwald walter at livinglogic.de
Thu Jul 7 23:31:35 CEST 2005


Am 07.07.2005 um 20:00 schrieb Guido van Rossum:

>>> +1 on @contextmanager
>
> +1.
>
> [__enter__, __exit__]
>
>>>> These names should be changed to __beginwith__ and __endwith__.
>>>>
>
> -1.  The PEP has had an extensive review period and several
> alternatives were discussed and rejected. These names are clear, they
> *do* match, and as Fred says the __*__ namespace has lots of room.
>
> Also, the PEP was accepted with these names. Now, if it was accepted
> with a major flaw or some semantics left unspecified,

What is still unspecified (or at least not explicitely mentioned) in  
the PEP is the lifetime of VAR in:

         with EXPR as VAR:
             BLOCK

Does VAR overwrite or shadow any previous values of VAR? I.e. will  
VAR still exist after the end of the block with its value the return  
value of __enter__() or will it revert to the previous value (if  
any)? I'd prefer the later although interpreting the translation of

         with EXPR as VAR:
             BLOCK

into

         abc = EXPR
         exc = (None, None, None)
         VAR = abc.__enter__()
         try:
             try:
                 BLOCK
             except:
                 exc = sys.exc_info()
                 raise
         finally:
             abc.__exit__(*exc)


literally would indicate the former.

Bye,
    Walter Dörwald



More information about the Python-Dev mailing list