[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20

Chris Angelico rosuav at gmail.com
Wed Apr 25 18:38:51 EDT 2018


On Thu, Apr 26, 2018 at 8:08 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Wed, 25 Apr 2018 16:55:43 -0500
> Tim Peters <tim.peters at gmail.com> wrote:
>>
>> To my eyes, this is genuinely harder to follow, despite its relative brevity:
>>
>>         while total != (total := total + term):
>
> Does it even work?  Perhaps if the goal is to stop when total is NaN,
> but otherwise?

Yes, it does, because the first "total" is looked up before the
rebinding happens. It's 100% unambiguous to the compiler... but still
pretty unclear to a human. And I think the multiple use of 'total' is
to blame for that. So I agree with Tim that this particular example is
better in longhand.

ChrisA


More information about the Python-Dev mailing list