[Python-Dev] Merging PEP 310 and PEP 340-redux?
Brett C.
bac at OCF.Berkeley.EDU
Fri May 13 22:29:06 CEST 2005
Guido van Rossum wrote:
[SNIP]
> Straight up-or-down votes in the full senate are appreciated at this point.
>
PEP 340 redux gets my +1; I think using generators will become more obviously
useful to people when, as Fredrick pointed out, your code grows more than a few
lines long.
> On to the secondary questions:
>
> - Today I like the 'do' keyword better; 'with' might confuse folks
> coming from Pascal or VB
>
-0; I can deal with either, but I just like how 'with' reads more.
> - I have a more elaborate proposal for __exit__'s arguments. Let the
> translation be as follows:
>
> abc = EXPR
> [VAR =] abc.__enter__()
> oke = False # Pronounced "okay"
> exc = ()
> try:
> try:
> BLOCK
> oke = True
> except:
> exc = sys.exc_info()
> raise
> finally:
> abc.__exit__(oke, *exc)
>
> This means that __exit__ can be called with the following arguments:
>
> abc.__exit__(True) - normal completion of BLOCK
>
> abc.__exit__(False) - BLOCK was left by a non-local goto (break/continue/return)
>
> abc.__exit__(False, t, v, tb) - BLOCK was left by an exception
>
> (An alternative would be to always call it with 4 arguments, the last
> three being None in the first two cases.)
>
> If we adopt PEP 340 redux, it's up to the decorator for degenerate
> generators to decide how to pass this information into the generator;
> if we adopt PEP 342 ("continue EXPR") at the same time, we can let the
> yield-expression return a 4-tuple (oke, t, v, tb). Most templates can
> ignore this information (so they can just use a yield-statement).
>
I think a later email discussed just passing in the values from sys.exc_info(),
and I like that more since it will be None if no exception was raised and thus
straight-forward to detect without being overly verbose with the oke argument.
-Brett
More information about the Python-Dev
mailing list