Open
Description
Bug Report
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[K, V], /) -> dict[K, V]: ...
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[str, V], /, **kwargs: V) -> dict[str, V]: ...
Return types are compatible.
class FrozendictBase(Generic[K, V]):
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[K, V],
/,
) -> 'FrozendictBase[K, V]': ...
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[str, V],
/,
**kwargs: V,
) -> 'FrozendictBase[str, V]': ...
Return types are also compatible, but mypy reports an error.
To Reproduce
- Download file.txt and save as
sandbox.py
. - Run
mypy sandbox.py
.
Expected Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
This is due to #5775.
Actual Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
sandbox.py:39: error: Overloaded function signatures 3 and 4 overlap with incompatible return types
sandbox.py:54: error: Overloaded function signatures 5 and 6 overlap with incompatible return types
Your Environment
- Mypy version used: mypy 0.950
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used: Python 3.10.4
- Operating system and version: Windows 10