[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Examples for PEP 572

On Wed, Jul 4, 2018 at 7:42 PM Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Jul 04, 2018 at 01:00:41PM -0700, Devin Jeanpierre wrote:
> > On Wed, Jul 4, 2018 at 11:04 AM Steven D'Aprano <steve at pearwood.info> wrote:
> > > Did you actually mean arbitrary simple statements?
> > >
> > > if import math; mylist.sort(); print("WTF am I reading?"); True:
> > >     pass
> >
> > Yes.
> Okay, you just broke my brain.
> I was *sure* that you were going to complain that I was misrepresenting
> your position, or attacking a strawman, or something.

This "brain-breaking" experience is something to keep in mind when we
read the reactions to the acceptance assignment expressions, so that
we can better empathize with the people who are so shocked by it.
After all, assignment expressions allow nearly word for word the same
abuse you posted:

if [(math := __import__('math')), mylist.sort(), print('WTF?'), True][-1]:

Anything that allows assignment in an if statement is going to allow
some messed up stuff. The PEP seems to intentionally take the stance
that it is OK to allow super-ugly code, because we can trust people to
just not do that.

> I did not imagine for a second that you *actually* would prefer
> to allow the above code over assignment expressions.

I don't really know how to bridge that disconnect. I thought Nathaniel
argued very well what is lost with assignment expressions.

-- Devin