Skip to content

NAM105: a query that returns nothing

Junior

A name that starts with a value verb, such as get_, find_, compute_, count_, to_ or format_, promises a value. Callers write total = get_total().

def get_total(self):  # NAM105: returns nothing
    self.total = sum(self.items)


def compute_total(self):  # returns what its name promises
    return sum(self.items)

A function like the first one returns None. The caller's total is None, and the error appears later, somewhere else.

To fix it, return the value, or rename the function after what it does: update_total, store_total.

Senior

This usually happens when a function that used to return a value was changed to store it on self, or when it writes its result into an argument. click's format_help(ctx, formatter) writes into the formatter it is given, which is a legitimate design that a value verb describes badly.

It stays quiet on:

  • private and dunder names, and bare one-word names like get.
  • an explicit return None, which states that "nothing" is a valid answer. importlib's get_source() returns None to mean "no source".
  • a declaration: @abstractmethod, @overload, or a stub body (..., pass, a docstring).
  • a function that ends by raising.
  • a generator.

If the function is a callback whose name a framework imposes, add it to the allowlist.

Expert

The value verbs are get, find, compute, calc, calculate, count, lookup, as, to and format. get_ returns a value in 916 of the corpus's 921 public get_ functions, which is why it qualifies. The check fires when no return in the function's own body has a value. A function with only bare return statements, or none, falls through to an implicit None.

The corpus rate is 0.27 per thousand in CPython and 6.18 in click. The click findings are its format_*(ctx, formatter) family. They are correct about the code. The convention there is the library's own, so a click user would allowlist them.