[Python-Dev] PEP 343 and with (original) (raw)

Jason Orendorff jason.orendorff at gmail.com
Tue Oct 4 16:51:11 CEST 2005


Right after I sent the preceding message I got a funny feeling I'm wasting everybody's time here. I apologize. Guido's original concern about speedy C implementation for locks stands. I don't see a good way around it.

By the way, my expansion of 'with' using coroutines (in previous message) was incorrect. The corrected version is shorter; see below.

-j

This:

with EXPR as VAR:
    BLOCK

would expand to this under PEP 342 and my proposal:

_cm = (EXPR).__with__()
VAR = _cm.next()
try:
    BLOCK
except:
    _cm.throw(*sys.exc_info())
finally:
    try:
        _cm.next()
    except (StopIteration, GeneratorExit):
        pass
    else:
        raise RuntimeError("coroutine didn't finish")


More information about the Python-Dev mailing list