Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dosisod opened this issue Mar 4, 2023 · 0 comments
Open

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

dosisod opened this issue Mar 4, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@dosisod
Copy link

dosisod commented Mar 4, 2023

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!
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants