PY3.R1703

Simplifiable if-statement

Used when an if statement can be replaced with bool(test).

Noncompliant Code:

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

def is_flying_animal(an_object):
    if isinstance(an_object, Animal) and an_object in FLYING_THINGS:
        is_flying = True
    else:
        is_flying = False
    return is_flying

Compliant Code:

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

def is_flying_animal(an_object):
    is_flying = isinstance(an_object, Animal) and an_object.name in FLYING_THINGS
    return is_flying

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.