[Python-ideas] ``with from`` statement

Guido van Rossum guido at python.org
Sat Dec 22 20:09:22 CET 2012


On Sat, Dec 22, 2012 at 10:26 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Sat, 22 Dec 2012 19:25:32 +0200
> Andrew Svetlov <andrew.svetlov at gmail.com>
> wrote:
>> Python syntax looks like use of time machine day by day. I like it!
>
> Not sure I like "with yield from". How do you intend to explain that to
> an average programmer?

Break it down into pieces. The general form is

  with <expr>: <block>

where <expr> can take many forms, including

  yield from <expr>

we just have to handwave a bit about the priorities, but that's
usually okay. People do get

 x = yield from <expr>

It's just that currently somehow you have to surround "yield from
<expr>" in an extra pair of parentheses everywhere except on the RHS
of an assignment; my other pet peeve in this area is that you must
write

  return (yield from <expr>)

(which I end up writing fairly regularly).

I assume that if we can make the parens optional for assignment, we
can make them optional in other places.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list