Skip to main content

SKY-L003 · Logic and resilience

Comparison to True, False or None with ==

Low

The catalog gives no severity for this rule; the detector always reports LOW.

x == None, x == True and x == False ask the object whether it is equal, and an object's __eq__ can answer anything. x is None asks whether it is the one None object, which no class can change.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
Dangerous comparison
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A class with a custom __eq__, such as a mock or an ORM field, can make == None true or false when it should not. A check like user.is_admin == True also silently fails for truthy values such as 1 or "yes" coming from a form or a database.

What Skylos flags

documents/permissions.py · PythonReported on line 2
def can_delete(user, document):    if user.is_admin == True:        return True    if document.owner_id is None:        return False    return document.owner_id == user.id

What Skylos leaves alone

documents/permissions.py · Python
def can_delete(user, document, settings):    if settings.get("allow_delete") in (True, "1"):        return user.is_admin is True or document.owner_id == user.id    return False

Why Skylos leaves it alone

Only == and != with a literal True, False or None are reported. in (True, "1") is a membership test, is True is the identity check the rule asks for, and owner_id == user.id compares two values.

How Skylos decides

  1. Runs with --quality on Python files. Visits every comparison, including chains such as a == b == None.
  2. Reports each == or != whose right-hand side is the literal True, False or None. The left-hand side is not checked, so None == x is not reported.
  3. Does not know the type of the value: a NumPy array, a pandas column or a SQLAlchemy column is reported the same way as a plain variable.
  4. Reports LOW on the line where the comparison starts, once per matching operator.

How to fix it

Use is None for None. For booleans, test the value itself, or use is True when only the real True should pass.

documents/permissions.py · Python · the fix, against the flagged file
def can_delete(user, document):Removed:     if user.is_admin == True:Added:     if user.is_admin is True:        return True    if document.owner_id is None:        return False    return document.owner_id == user.id

When it can be wrong

  • Libraries that build expressions from == need it. In SQLAlchemy, User.deleted_at == None becomes deleted_at IS NULL in SQL, while is None is plain Python and always false. In pandas and NumPy, df["active"] == True compares each element. Both are reported; keep them and suppress, or use .is_(None) and df["active"].eq(True).
  • None == x, with the literal on the left, is not reported.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on the line where the comparison starts.

    Python
    query = query.filter(User.deleted_at == None)  # skylos: ignore[SKY-L003] SQL IS NULL
  • [tool.skylos] ignore = ["SKY-L003"] turns the rule off for the project, which suits code bases built on SQLAlchemy or pandas.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.