MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
187 stars 19 forks source link

[Adjust Rule] Only emit SIM208 in boolean contexts #170

Open dosisod opened 1 year ago

dosisod commented 1 year ago

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