[Python-Dev] PEP 343 - Abstract Block Redux

Nick Coghlan ncoghlan at gmail.com
Sat May 14 10:33:25 CEST 2005


Robert Brewer wrote:
> There's a typo in the code snippets at the moment.
> 
>         The translation of the above statement is:
> 
>         abc = EXPR
>         exc = ()  # Or (None, None, None) ?
>         try:
>             try:
>                 VAR = abc.__enter__()
>                 BLOCK
>             except:
>                 exc = sys.exc_info()
>                 raise
>         finally:
>             abc.__exit__(exc)
> 
> I think you meant "abc.__exit__(*exc)". Assuming that, then "exc =
> (None, None, None)" makes the most sense. If exc_info() is going to be
> passed as a single arg, then I'd rather have the default "exc = ()", so
> I can simply check "if exc:" in the __exit__ method.

Also, the call to __enter__() needs to be before the try/finally block (as it is 
in PEP 310). Otherwise we get the "releasing a lock you failed to acquire" problem.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list