missing-return (ODW8110)
Preview (since 0.16.2.2) · Related issues · View source
Derived from the odoo linter.
Fix is sometimes available.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks that a method calling super() also has a return statement.
Why is this bad?
A method that calls super() but never returns its result (or any other value) usually
means the return value of the base implementation is silently dropped.
Example
Use instead:
Fix safety
Every fix requires the method to call super() exactly once: with two calls, the value to
hand back is a choice between them, and choosing is the author's job. Given that single
call, there are two shapes where what to return is not a guess:
- the call is the method's last statement, and the
returngoes in front of it. Nothing can be skipped by returning there, because nothing runs after it. - the call's result is assigned to a plain variable (
res = super().default_get(fields)) at the top level of the method, andreturn resis appended at the end. Whatever the method does toresin between,resis the value it was building.
Anything else keeps the bare report: the call made inside an if or a loop, or its result
assigned there, where the name may never be bound; the assignment target a tuple, an
attribute or a subscript rather than a plain name; a method ending in raise, where the
return would be dead code; and a call further down a chain, whose value is no longer the
base implementation's.
The fix is marked unsafe because it changes what the method returns: callers that relied on
the None of an implicit return now see the value the method was building. That is the
point of the rule, but it is still a behavior change, and dropping the result is
occasionally deliberate.
Options
Names the methods exempt from returning, not the ones checked.