[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)

Steven D'Aprano steve at pearwood.info
Wed Jun 27 03:42:25 EDT 2018

On Tue, Jun 26, 2018 at 10:54:12AM +1200, Greg Ewing wrote:

> A decision still needs to be made about whether we *want*
> semantics that leak some things but not others.

My sense (or bias, if you prefer) is that the answer to that depends 
on how you word the question. If you talk about "leaking", or 
give examples with trivial 1-character names that look all too 
easy to accidentally clobber, people will say "No":

    # Given this:
    x = 999
    [(x := i)*x for i in (1, 2)]

    # should print(x) afterwards result in 4?

but if you show a useful example that doesn't look like an accident 
waiting to happen, but a deliberate feature:

    # Given this:
    previous = 0
    [previous + (previous := i) for i in (1, 2, 3)]

    # what value would you expect previous to have
    # at the completion of the loop?

they'll be more receptive to the idea. (If they're not opposed to 
assignment expressions at all.)

Avoiding leading questions is *hard*, and I believe that in general 
people don't know what they want until they've got it. I say that from 
considering all the times I've made a radical about face, features which 
I was *sure* would be awful actually turned out to be not awful at all 
-- augmented assignment, for instance.


More information about the Python-Dev mailing list