[Python-3000] self-contained exceptions

Guido van Rossum guido at python.org
Thu Jan 11 17:36:31 CET 2007


Let me clarify. I have no desire to prevent tuple assignment in with
statements. But I do think that the tuples could be limited to plain
names and other tuples (with similar constraints), and those names
should all be zapped at the end of the clause, like for except. And we
don't even have to add an extra try/finally to do so, since with
already *has* a try/finally...

I'm also curious to hear what people think of similarly limiting the
syntax of the target in all for-loops -- but WITHOUT the zapping of
the variable at block end.

I think none of these changes would affect reasonably written code;
the use cases for using variables that are part of other objects are
too obscure to care.

--Guido

On 1/11/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 12:37 AM 1/12/2007 +1000, Nick Coghlan wrote:
> >Phillip J. Eby wrote:
> >>At 07:47 AM 1/10/2007 -0800, Guido van Rossum wrote:
> >>>BTW perhaps we should add the same semantics and syntax to 'with expr
> >>>as var'? I can't think of a reasonable use case
> >>[snip]
> >>>... for using anything
> >>>more complex than a local variable, BTW.)
> >>with multi(ctx1, ctx2, ...)  as var1, var2, ...:
> >>(if multi is a function that returns a context manager wrapping the other
> >>contexts and returning the tuple their __enter__ values).
> >
> >...a utility which is also known as contextlib.nested().
> >
> >For some strange reason, I suspect you're familiar with that particular
> >context manager ;)
>
> Not that I recall, no, otherwise I'd have used the name.  I thought there
> was such a thing in the PEP, but didn't know it had gotten in the stdlib
> (which of course is an even better reason to keep tuple assignment in the
> "with" statement).
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list