Mypy incorrectly complains about the return statement in this program (with --strict-optional):
def f() -> str:
y # Causes f to be deferred
x = None
if int():
x = ''
if x is None:
x = ''
return x # Incompatible return value type (got "Optional[Any]", expected "str")
y = int()
The expected behavior is clean output.
Note that f is deferred. The problem goes away when f is not deferred.