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

Nathan Schneider neatnate at gmail.com
Wed Apr 11 18:01:39 EDT 2018


On Wed, Apr 11, 2018 at 1:49 PM, Brendan Barnwell <brenbarn at brenbarn.net>
wrote:

> On 2018-04-11 05:23, Clint Hepner wrote:
>
>> I find the assignments make it difficult to pick out what the final
>> expression looks like.
>>
>
>         I strongly agree with this, and for me I think this is enough to
> push me to -1 on the whole proposal.  For me the classic example case is
> still the quadratic formula type of thing:
>
> x1, x2 = (-b + sqrt(b**2 - 4*a*c))/2, (-b - sqrt(b**2 - 4*a*c))/2
>
>         It just doesn't seem worth it to me to create an expression-level
> assignment unless it can make things like this not just less verbose but at
> the same time more readable.  I don't consider this more readable:
>
> x1, x2 = (-b + sqrt(D := b**2 - 4*a*c)))/2, (-b - sqrt(D))/2
> <http://python.org/psf/codeofconduct/>
>

I'd probably write this as:

x1, x2 = [(-b + s*sqrt(b**2 - 4*a*c))/(2*a) for s in (1,-1)]

Agreed that the PEP doesn't really help for this use case, but I don't
think it has to. The main use cases in the PEP seem compelling enough to me.

Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180411/3a6ca42b/attachment.html>


More information about the Python-ideas mailing list