Closed
Description
Consider this (oversimplified) example:
from typing import TypeVar, Optional
T = TypeVar('T')
def f(x: Optional[T] = None) -> T: ...
x = f() # Need type annotation for 'x'
y = x # Cannot determine type of 'x'
def g() -> None:
x = f() # Need type annotation for 'x'
y = x # Cannot determine type of 'x'
The subsequent errors look redundant (and maybe even annoying). This is more important with the new semantic analyzer because the old one doesn't show the error if the problematic variable was defined at the function scope.
Potentially, we can replace <nothing>
with Any
after we show the error. Also the code that detects failed inference can be improved. For example, is_valid_inferred_type()
should be replaced with a proper type visitor.