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:
- # Error: Missing return statement [return]
- def show(x: int) -> int:
- print(x)
- # Error: Missing return statement [return]
- def pred1(x: int) -> int:
- if x > 0:
- return x - 1
- # OK
- def pred2(x: int) -> int:
- if x > 0:
- return x - 1
- else:
- raise ValueError('not defined for zero')