flake8-simplify icon indicating copy to clipboard operation
flake8-simplify copied to clipboard

[Adjust Rule] Only emit SIM208 in boolean contexts

Open dosisod opened this issue 1 year ago • 0 comments

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!
    ...

dosisod avatar Mar 04 '23 00:03 dosisod