Too many boolean expressions in if statement

Viewed 440

I have this warning in Lint: R0916: Too many boolean expressions in if statement (6/5) (too-many-boolean-expressions)

Thats my code:

if (
    old_image.get("var") == "Type1"
    or old_image.get("var") == "Type2"
    or old_image.get("var") == "Type3"
) and (
    new_image.get("var") != "Type1"
    and new_image.get("var") != "Type2"
    and new_image.get("var") != "Type3"
):

How do I remove this lint error?

1 Answers

You can try this:

types = [ "Type1", "Type2", "Type3"]
if old_image.get("var") in types and new_image.get("var") not in types:
Related