simplifiable-if-expression / R1719ΒΆ

Message emitted:

The if expression can be replaced with %s

Description:

Used when an if expression can be replaced with 'bool(test)' or simply 'test' if the boolean cast is implicit.

Problematic code:

FLYING_THINGS = ["bird", "plane", "superman", "this example"]


def is_flying_thing(an_object):
    return True if an_object in FLYING_THINGS else False  # [simplifiable-if-expression]


def is_not_flying_thing(an_object):
    return False if an_object in FLYING_THINGS else True  # [simplifiable-if-expression]

Correct code:

FLYING_THINGS = ["bird", "plane", "superman", "this example"]


def is_flying_thing(an_object):
    return an_object in FLYING_THINGS


def is_not_flying_thing(an_object):
    return an_object not in FLYING_THINGS

Related links:

Created by the refactoring checker.