Closed
Description
The first call to g
generates an error, but the second one doesn't:
from typing import TypeVar, Callable, Iterable, Optional, List, Any
T = TypeVar("T")
def g(f: Callable[[T, T], T], seq: Iterable[Optional[T]]) -> Optional[T]: ...
a: List[Any]
# Incompatible types in assignment (expression has type "Optional[SupportsLessThanT]", variable has type "Optional[int]")
b: Optional[int] = g(min, a) # Error!
a2: List[int]
b2: Optional[int] = g(min, a2) # No error
The only difference between the cases is that the first one has a less precise type (List[Any]
vs List[int]
). Making a type less precise shouldn't generate more type errors, so this is arguably a bug. We should probably propagate the Any
type from List[Any]
to the return type.