chained-comparison-all-equal / R1738ΒΆ

Message emitted:

Simplify chained comparison cycle to equality between the operands: %s

Description:

Emitted when the operands of a boolean condition form a cycle of weak inequalities (``<=`` or ``>=``). The condition is equivalent to checking that all the operands are equal.

Problematic code:

def baskets_hold_the_same(red, green):
    # Each basket holds at least as many apples as the other, so the two
    # baskets hold the same number.
    return red >= green and green >= red  # [chained-comparison-all-equal]

Correct code:

def baskets_hold_the_same(red, green):
    return red == green

Created by the refactoring checker.