SKY-L003 · Logic and resilience
Comparison to True, False or None with ==
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
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
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.idWhat Skylos leaves alone
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 FalseWhy 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
- Runs with
--qualityon Python files. Visits every comparison, including chains such asa == b == None. - Reports each
==or!=whose right-hand side is the literalTrue,FalseorNone. The left-hand side is not checked, soNone == xis not reported. - 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.
- 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.
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.idWhen it can be wrong
- Libraries that build expressions from
==need it. In SQLAlchemy,User.deleted_at == Nonebecomesdeleted_at IS NULLin SQL, whileis Noneis plain Python and always false. In pandas and NumPy,df["active"] == Truecompares each element. Both are reported; keep them and suppress, or use.is_(None)anddf["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.