Open
Description
False positive; mypy doesn't believe that Foo[T]
is a subtype of T
.
from typing import Union, Generic, TypeVar, overload
T = TypeVar("T")
class Foo(Generic[T]):
pass
@overload
def expect(pattern: Foo[T]) -> None: ...
@overload
def expect(pattern: T) -> None: ...
def expect(pattern: Union[Foo[T], T]) -> None: return None
$ mypy xxx.py
xxx.py:14: error: Overloaded function implementation does not accept all possible arguments of signature 1
Note that the second overload referencing the type variable used in the first overload is necessary; if pattern: int
is used instead of pattern: T
in the second overload, mypy type-checks the file correctly.
Environment
- Mypy version used: 0.910
- Python version used: 3.10 and 3.7
- Operating system and version: Fedora 34
Related issues
- Wrong "Overloaded function implementation does not accept all possible arguments" #11004: mypy thinks
**kwargs: Union[None, int, str]
overload isn't accepted by**kwargs: Any
- Overloads with type variables and generic types are incorrectly rejected #9420: mypy thinks
Type[T1]
isn't accepted byUnion[Type[T1], Type[T2]]
- False positive when type checking overloads with generics #9023: same bug with two different type variables
I think that #10390 fixes this issue, but I'm not sure.