On Sun, May 13, 2018 at 8:47 AM, Juancarlo Añez <apal...@gmail.com> wrote:
>
>> My main point here is that "with" works as well as "given" in this form
>> from an English prose point of view.
>
>
> +1 for "with...as", -1 for ":="
>
> About affecting existing contexts, it seems that "with..as" would create a
> new context just for the expression, and the control statement it is
> embedded in, similar to what the current "with" statement does. These are
> semantics that are really easy to explain.

The trouble with every variant involving 'with' is that the semantics
LOOK similar, but are subtly different. The current 'with' statement
doesn't create a subscope; the only "context" it creates is regarding
the resource represented by the context manager. For instance, opening
a file in a 'with' block will close the file at the end of the block -
but you still have a (closed) file object. Using "with... as" for name
bindings wouldn't call __enter__ or __exit__, so it won't create that
kind of context; and whether it creates a subscope for the variable or
not, it's not going to match the 'with' statement.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to