[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
Tim Peters
tim.peters at gmail.com
Wed Apr 25 18:22:23 EDT 2018
[Tim]
>> To my eyes, this is genuinely harder to follow, despite its relative brevity:
>>
>> while total != (total := total + term):
[Antoine]
> Does it even work? Perhaps if the goal is to stop when total is NaN,
> but otherwise?
I don't follow you. You snipped all the text explaining why it would
work, so trying reading that again? When, e.g., `total` reaches 1.0
and `term` reaches 1e-30, this becomes:
while 1.0 != (total := 1.0 + 1-e30):
which leaves `total` unchanged (1.0 + 1e-30 == 1.0) and then
while 1.0 != 1.0:
causes the loop to exit (`while False:`).
>> For that reason, the messages that sway me are those showing real
>> code, or at least plausibly realistic code. In the majority of those
>> so far, binding expressions would be a small-to-major win.
> I'm sure it's possible to find thousands of line of code where binding
> expressions wouldn't be a win, but I'm not sure that would be a
> constructive use of mailing-list bandwidth.
And that "argument" is? ;-)
Note that I managed to move the PEP _away_ from general "assignment
expressions" to the much simpler "binding expressions" precisely _by_
illustrating, via real code, why the generality of the former wasn't
actually useful in any case I looked at. If something is always - or
almost always - useless, that can be shown via considering realistic
code. That was far more productive than endless abstract debates.
More information about the Python-Dev
mailing list