[Python-ideas] PEP 572: Assignment Expressions (post #4)

Ethan Furman ethan at stoneleaf.us
Wed Apr 11 19:03:27 EDT 2018


On 04/11/2018 02:55 PM, Chris Angelico wrote:
> On Thu, Apr 12, 2018 at 4:38 AM, Ethan Furman wrote:

> Context managers and except blocks don't do the same thing though, so
> it's a false parallel.

They assign things to names using `as`.  Close enough.  ;)


> The other two are
> *dangerous* false parallels, because "with foo as bar:" is
> semantically different from "with (foo as bar):";

If `with` is the first token on the line, then the context manager syntax should be enforced -- you get one or the 
other, not both.


>> - puts the calculation first, which is what we are used to seeing in
>> if/while statements; and
>
> Not sure what you mean here; if and while statements don't have
> anything BUT the calculation.

Which is why we're using to seeing it first.  ;)

> A 'for' loop puts the targets before the evaluated expression.

Hmm, good point -- but it still uses a key word, `in`, to delineate between the two.

>> - matches already existing expression-level assignments (context managers,
>> try/except blocks)
>
> They're not expression-level assignments though, or else I'm
> misunderstanding something here?

No, just me being sloppy with vocabulary.

--
~Ethan~


More information about the Python-ideas mailing list