SKY-L006 · Logic and resilience
Inconsistent return
A function that returns a value on some paths and uses a bare return on others mixes two styles. Callers cannot tell whether the bare return means "no result" on purpose or is a path someone forgot.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- Shadowed loop variable
Why it matters
The caller gets None where it expects a number, and the error shows up later, far from its cause: here price * (100 - find_discount(code)) / 100 raises TypeError for an empty code instead of applying no discount.
What Skylos flags
def find_discount(code, discounts): if not code: return for discount in discounts: if discount.code == code.upper(): return discount.percent return 0What Skylos leaves alone
def find_discount(code, discounts) -> int | None: if not code: return for discount in discounts: if discount.code == code.upper(): return discount.percent return 0Why Skylos leaves it alone
The return annotation int | None says None is a valid result, so the bare return is a declared outcome. Skylos skips functions whose annotation allows None (Optional[...], Union[..., None], X | None or None).
How Skylos decides
- Runs with
--qualityon Python files and visits everydefandasync def. - Skips the function when its return annotation allows
None. - Collects the
returnstatements of the function itself, not of nested functions or classes. Areturnwith a value other thanNonecounts as a value return; a barereturncounts as a bare one. An explicitreturn Nonecounts as neither, as PEP 8 recommends. - Reports MEDIUM on the
defline when the function has both. A function that returns a value on some paths and simply ends on others, with no barereturn, is not reported.
How to fix it
Return the same kind of value on every path. Here an empty code means no discount, so return 0. When None is a real answer, write return None or annotate the function with | None.
def find_discount(code, discounts): if not code:Removed: returnAdded: return 0 for discount in discounts: if discount.code == code.upper(): return discount.percent return 0When it can be wrong
- Functions that mean "no result" with a bare
returnand document it only in the docstring are reported; add the annotation or writereturn None. - A function that falls off its end on some paths (an implicit
None) is not reported, even though it has the same problem.
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
defline (the first line of a multi-line signature).Python def find_discount(code, discounts): # skylos: ignore[SKY-L006] legacy API[tool.skylos] ignore = ["SKY-L006"]turns the rule off for the project.