On 25 Apr, 2018, at 1:24 PM, Chris Angelico rosuav@gmail.com wrote:
On Thu, Apr 26, 2018 at 6:21 AM, Łukasz Langa lukasz@langa.pl wrote:
:= also goes against having one obvious way to do it. Since it's an expression, it can also be placed on its own line or in otherwise weird places like function call arguments. I anticipate PEP 8 would have to be extended to explicitly discourage such abuse. Linters would grow rules against it. This is noise.
Does this argument also apply to the if/else expression? Do linters need rules to advise against people writing code like:
print(x) if x is None else print(y)
? It's perfectly legal to write code like this. But I don't see people abusing this sort of thing.
Ternary expressions are different because their flow is deliberately different
from a regular if statement. It's also different from the C equivalent.
:=
on the other hand is deciptively similar to =
.
But yeah, I think worrying about abuse of the feature is a red herring. The gist of my criticism of your PEP is about the decreased balance in information density.
-- Ł