-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct code
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 errorThe 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.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct code