3 ms·
To add to the cacaphony of counterarguments to this, this can introduce nonobvious bugs when refactoring. If the condition-guarded statement is nontrivial and
by joshuamorton 5y ago
To add to the cacaphony of counterarguments to this, this can introduce nonobvious bugs when refactoring.
If the condition-guarded statement is nontrivial and you remove the assignment, everything stays valid. If otoh you use a ternary or
if x:
y = 1
else:
y = 2
If you now delete the else block or something (like the assignment from a larger else block), a linter can warn you that y is undefined. Otherwise you'd need a test to ensure correctness.