PY3.R1719

Simplifiable if-expression

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

Noncompliant Code:

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

def is_flying_thing(an_object):
    return True if an_object in FLYING_THINGS else False

def is_not_flying_thing(an_object):
    return False if an_object in FLYING_THINGS else True

Compliant Code:

Copy
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

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.