Skip to main content

SKY-L006 · Logic and resilience

Inconsistent return

Medium

The catalog gives no severity for this rule; the detector always reports MEDIUM. The catalog names the rule "Shadowed loop variable", but the detector checks return statements; this page describes the detector.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

shop/discounts.py · PythonReported on line 1
def find_discount(code, discounts):    if not code:        return    for discount in discounts:        if discount.code == code.upper():            return discount.percent    return 0

What Skylos leaves alone

shop/discounts.py · Python
def find_discount(code, discounts) -> int | None:    if not code:        return    for discount in discounts:        if discount.code == code.upper():            return discount.percent    return 0

Why 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

  1. Runs with --quality on Python files and visits every def and async def.
  2. Skips the function when its return annotation allows None.
  3. Collects the return statements of the function itself, not of nested functions or classes. A return with a value other than None counts as a value return; a bare return counts as a bare one. An explicit return None counts as neither, as PEP 8 recommends.
  4. Reports MEDIUM on the def line when the function has both. A function that returns a value on some paths and simply ends on others, with no bare return, 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.

shop/discounts.py · Python · the fix, against the flagged file
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 0

When it can be wrong

  • Functions that mean "no result" with a bare return and document it only in the docstring are reported; add the annotation or write return 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 def line (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.

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