Open
Description
Bug Report
Parameterized protocols seem to be largely or totally ignored when specified as argument types. Simple example:
from typing import Protocol, TypeVar
T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)
class Proto(Protocol[T_co]):
def __call__(self, *, a: str) -> T_co:
...
class InvalidClass:
def __init__(self, *, a: int) -> None:
...
def test(b: Proto[T]) -> T:
return b(a="0")
test(InvalidClass) # <-- should fail type checking
InvalidClass is accepted here even though it does not conform to the protocol. Here's a more detailed playground gist.
As demonstrated in the gist, the issue does not reproduce when a function is provided, only with a class. It also does not manifest with assignment, only with arguments. However, assigning with the parameter set to Any also produces an unexpected result, which might somehow be related.
- Mypy version used: 1.0
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used: 3.11