Check that function does not return Any value [no-any-return]
If you use —warn-return-any
, mypy generates an error if you return avalue with an Any
type in a function that is annotated to return anon-Any
value.
Example:
- # mypy: warn-return-any
- def fields(s):
- return s.split(',')
- def first_field(x: str) -> str:
- # Error: Returning Any from function declared to return "str" [no-any-return]
- return fields(x)[0]