Check that function returns a value [return]

If a function has a non-None return type, mypy expects that thefunction always explicitly returns a value (or raises an exception).The function should not fall off the end of the function, since thisis often a bug.

Example:

  1. # Error: Missing return statement [return]
  2. def show(x: int) -> int:
  3. print(x)
  4.  
  5. # Error: Missing return statement [return]
  6. def pred1(x: int) -> int:
  7. if x > 0:
  8. return x - 1
  9.  
  10. # OK
  11. def pred2(x: int) -> int:
  12. if x > 0:
  13. return x - 1
  14. else:
  15. raise ValueError('not defined for zero')