SKY-L037 · Logic and resilience
Conditional returning bool literals
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-adviceor select the rule (--select SKY-L037). - Finding type
- advice
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
"""Invoice status helpers.""" def is_overdue(invoice, today): return True if invoice.due_date < today else FalseWhat Skylos leaves alone
"""Invoice status helpers.""" def is_overdue(invoice, today): if invoice.paid: return False elif invoice.due_date < today: return True else: return FalseWhy 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
- Runs with
--qualityon Python files. Looks at conditional expressions (a if c else b) and atif/elsestatements whose branches each hold onereturnor one assignment to the same name. - Reports when the two outcomes are the opposite literals
TrueandFalse.eliflinks of a chain are skipped. - For
False if c else True, skips a condition that is an==,<or similar comparison:a != bneed not be its opposite for overloaded types (numpy arrays, SQLAlchemy columns), andnot (a == b)is itself a lint finding. - Suggests the condition itself when it is always a bool (
is,in,not,isinstance(),any()and similar), andbool(...)around it otherwise. - Skips files where the project's ruff configuration ignores
SIM103,SIM210orSIM211, 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().
"""Invoice status helpers.""" def is_overdue(invoice, today):Removed: return True if invoice.due_date < today else FalseAdded: return invoice.due_date < todayWhen it can be wrong
- This is style advice: the code is not wrong. A team that prefers the explicit
if/elsefor 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, theifline).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'sSIM103,SIM210orSIM211in the project's ruff configuration also turns it off.