consider-using-in / R1714ΒΆ

Message emitted:

Consider merging these comparisons with 'in' by using '%s %sin (%s)'. Use a set instead if elements are hashable.

Description:

To check if a variable is equal to one of many values, combine the values into a set or tuple and check if the variable is contained "in" it instead of checking for equality against each of the values. This is faster and less verbose.

Problematic code:

def fruit_is_round(fruit):
    # +1: [consider-using-in]
    return fruit == "apple" or fruit == "orange" or fruit == "melon"

Correct code:

def fruit_is_round(fruit):
    return fruit in {"apple", "orange", "melon"}

Created by the refactoring checker.