[Python-Dev] PEP 572: Assignment Expressions

Steve Holden steve at holdenweb.com
Mon Apr 23 11:59:35 EDT 2018


On Mon, Apr 23, 2018 at 8:28 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:

> On Mon, 23 Apr 2018 00:44:44 -0500
> Tim Peters <tim.peters at gmail.com> wrote:
> ​[...]
>
> > if (diff := x - x_base) and (g := gcd(diff, n)) > 1:
> >     return g
> > That's so Pythonic I could cry ;-)
>
> ​[...]
>
> The second part, especially, where you use the result of an
> assignment expression as a comparison operand, looks definitely
> un-Pythonic.
>
> ​Which, I suppose, underlines that Pythonicity is in the mind of the
beholder.​


The assignment expression seems like a vary natural way to introduce
variables of limited (controlled?) scope, and the class-namespace special
case doesn't seem horrible enough to put me, at least, off the idea. There
will, of course, be those who abuse assignment expressions, and I'm very
much looking forward to seeing what David Beazley makes of them.

While Tim's expression might look (superficially) like C, the five-line
alternative isn't exactly an inspiring example of Pythonicity, is it?

regards
 Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180423/b4608ec6/attachment.html>


More information about the Python-Dev mailing list