Re:PEP 572: Python assignment expressions has been accepted
by sluukkonen on Tuesday July 03, 2018 @05:31AM
(#17448731)
Would've making regular assignment an expression broken too much existing code?
[ Parent
| on HN ]
Re:PEP 572: Python assignment expressions has been accepted
by sametmax on Tuesday July 03, 2018 @06:45AM
(#17449059)
It's a voluntary design choice since the beginning of Python to avoid the very common mistake of doing:
while continue = "yes":
instead of: while continue == "yes":
Those mistakes introduce bugs that are hard to spot because they don't cause an immediate error, linters can hardly help with them and even a senior can make them while being tired.
Re:PEP 572: Python assignment expressions has been accepted
by bluecalm on Tuesday July 03, 2018 @04:44PM
(#17453480)
I don't know about linters but GCC warns me about that every time I make that typo. They could just require parenthesis when assignment value is used as boolean.
Re:PEP 572: Python assignment expressions has been accepted
by icebraining on Tuesday July 03, 2018 @06:02AM
(#17448916)
Probably not, since expressions can already be statements. But that would allow dangerous code like "if a = 3", which I don't think the Python devs would want to allow.