PEP 572 implementation for Python

Andy Valencia vandys at vsta.org
Sun Jul 22 20:41:25 EDT 2018


Hi, just an FYI (and request for comments).

I've coded up PEP 572 on top of "Tauthon" (sometimes in early
days known as "Python 2.8"):

    https://github.com/vandys/tauthon (branch pep572)

After reading the PEP, Guido's comments, and looking at the code,
I realized that := just wants to be an augmented assignment
operator, and that what's really needed is to make all the augmented
assignment operators be expressions.

I also made them all *just* expressions, with higher precedence than
comma, but lower than the rest.  Also right associative, so:

    a := b := c := 1

does what you expect without any special "multi assignment" code,
but just because expressions with right association do the right
thing anyway.

As augmented assignments are now just expressions, you can do:

    while buf := ob.read():
	...

but also:

    if (self.count += 1) > PROBLEM:
	...

In the interests of orthogonality, I did *not* add code to disable
places where some expressions--but not these new ones--could be used.
Go ahead and say:

    a := 1

at the top level if that's what floats your boat.

Regards,
Andy Valencia


More information about the Python-list mailing list