Skip to main content

SKY-L037 · Logic and resilience

Conditional returning bool literals

Low

A conditional whose only job is to turn a condition into True or False: True if x else False, or an if/else that returns (or assigns) opposite bool literals. The condition can be used directly.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans). Only when listed. This is advice outside the default set: the report keeps it in JSON but does not list it, and the gate does not count it, unless you pass --all-advice or select the rule (--select SKY-L037).
Finding type
advice
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Four lines say what one expression says, and the reader has to check that the two branches really are opposite. Such code is typical of generated or hurried code and hides the actual condition.

What Skylos flags

billing/invoices.py · PythonReported on line 5
"""Invoice status helpers."""  def is_overdue(invoice, today):    return True if invoice.due_date < today else False

What Skylos leaves alone

billing/invoices.py · Python
"""Invoice status helpers."""  def is_overdue(invoice, today):    if invoice.paid:        return False    elif invoice.due_date < today:        return True    else:        return False

Why Skylos leaves it alone

The True/False pair belongs to an elif link of a longer chain. Folding just that link into one expression would not make the whole chain clearer, so Skylos leaves elif links alone.

How Skylos decides

  1. Runs with --quality on Python files. Looks at conditional expressions (a if c else b) and at if/else statements whose branches each hold one return or one assignment to the same name.
  2. Reports when the two outcomes are the opposite literals True and False. elif links of a chain are skipped.
  3. For False if c else True, skips a condition that is an ==, < or similar comparison: a != b need not be its opposite for overloaded types (numpy arrays, SQLAlchemy columns), and not (a == b) is itself a lint finding.
  4. Suggests the condition itself when it is always a bool (is, in, not, isinstance(), any() and similar), and bool(...) around it otherwise.
  5. Skips files where the project's ruff configuration ignores SIM103, SIM210 or SIM211, and golden test fixtures. Reports LOW on the line of the conditional.

How to fix it

Return the condition. A < comparison of dates already gives a bool; for a value that might not be one, wrap it in bool().

billing/invoices.py · Python · the fix, against the flagged file
"""Invoice status helpers."""  def is_overdue(invoice, today):Removed:     return True if invoice.due_date < today else FalseAdded:     return invoice.due_date < today

When it can be wrong

  • This is style advice: the code is not wrong. A team that prefers the explicit if/else for readability will see findings it does not want; turn the rule off in configuration.

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 reported line (for an if/else, the if line).

    Python
    return True if mask.any() else False  # skylos: ignore[SKY-L037] numpy
  • [tool.skylos] ignore = ["SKY-L037"] turns the rule off for the project. Ignoring ruff's SIM103, SIM210 or SIM211 in the project's ruff configuration also turns it off.

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