bad-chained-comparison / W3601#

Message emitted:

Suspicious %s-part chained comparison using semantically incompatible operators (%s)

Description:

Used when there is a chained comparison where one expression is part of two comparisons that belong to different semantic groups ("<" does not mean the same thing as "is", chaining them in "0 < x is None" is probably a mistake).

Problematic code:

def xor_check(*, left=None, right=None):
    if left is None != right is None:  # [bad-chained-comparison]
        raise ValueError('Either both left= and right= need to be provided or none should.')

Correct code:

def xor_check(*, left=None, right=None):
    if (left is None) != (right is None):
        raise ValueError('Either both left= and right= need to be provided or none should.')

Related links:

Created by the bad-chained-comparison checker.