flake8-simplify
flake8-simplify copied to clipboard
[Adjust Rule] Only emit SIM208 in boolean contexts
The SIM208
rule should be updated to only emit errors for not not x
in boolean contexts, since changing it to just x
can cause different results under certain circumstances.
Example
x = 123
y = not not x
In the above example, y
is True
, but changing it to y = x
turns it into 123
.
Solution
Only check when in a boolean context, such as an if
/while
clause:
x = ... # dont check here
if x: # ok to check
...
elif x: # and here
...
elif f(x): # but not here!
...