Skip to main content

SKY-T102 · Quality, structure and performance

Missing return type annotation

Low

The catalog gives no severity. Every finding is reported LOW.

A return annotation (-> str) states what a function gives back. SKY-T102 reports a public Python function or method without one, but only where the project has asked for annotations: when its own mypy settings require them, or when annotation advice is turned on.

Languages
Python
Turned on by
--quality, when the project's mypy settings require annotations or typing_coverage_advice = true is set under [tool.skylos]
Quality gate
counted toward the gate limits (full and diff scans). When it runs, it is listed and counted toward max_quality. Missing parameter types on the same function (SKY-T101) are shown in the same entry.
Needs
a mypy policy that requires annotations for the file (disallow_untyped_defs, disallow_incomplete_defs or strict), or typing_coverage_advice = true under [tool.skylos]
Finding type
advice
Catalog name
Missing return type annotations
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Without a declared return type, mypy treats the function as returning Any (or skips it), so every caller loses checking. A function that sometimes returns None then reaches code that calls .upper() on it.

What Skylos flags

app/pricing.py · PythonReported on line 6
"""Price formatting for invoices.""" from decimal import Decimal  def format_price(price: Decimal, currency: str):    return f"{price:.2f} {currency}"
pyproject.toml · TOML
[tool.mypy]files = ["app"]disallow_incomplete_defs = true

What Skylos leaves alone

app/pricing.py · Python
"""Price formatting for invoices.""" from decimal import Decimal  def format_price(price: Decimal, currency: str) -> str:    return f"{price:.2f} {currency}"  def legacy_total(items):    return sum(item.price for item in items)

pyproject.toml: same as in the flagged example.

Why Skylos leaves it alone

disallow_incomplete_defs only rejects functions that are partly annotated, as format_price was. legacy_total has no annotations at all, so mypy accepts it under this setting, and Skylos follows mypy.

How Skylos decides

  1. Runs with --quality, once per Python module, with the same scope as SKY-T101: public module-level functions and methods of public classes, restricted to a literal __all__ when there is one; test code, examples, benchmarks, a top-level docs folder and the root setup.py are skipped unless the mypy policy covers them.
  2. Reads the project's mypy settings and requires a return type where mypy would: on every public function with disallow_untyped_defs or strict, and only on partly annotated ones with disallow_incomplete_defs. The file must be among the files mypy checks (files or a command's targets). A # type: comment counts.
  3. With typing_coverage_advice = true under [tool.skylos] and no such requirement, it reports functions that are explicitly part of an API, such as names in a literal __all__; a plain procedure that never returns a value is then not reported.
  4. Reports LOW on the def line.

How to fix it

Add the return type. For a function that returns nothing, write -> None.

app/pricing.py · Python · the fix, against the flagged file
"""Price formatting for invoices.""" from decimal import Decimal  Removed: def format_price(price: Decimal, currency: str):Added: def format_price(price: Decimal, currency: str) -> str:    return f"{price:.2f} {currency}"

When it can be wrong

  • Under a mypy requirement, a function that only performs an action without -> None is reported, as mypy would report it.
  • It misses private functions (names starting with _) and nested functions, which mypy still checks.

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

  • On the def line (the reported line):

    Python
    def format_price(price: Decimal, currency: str):  # skylos: ignore[SKY-T102] stub
  • ignore = ["SKY-T102"] under [tool.skylos] turns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.

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