Closed
Description
from dataclasses import dataclass
from typing import Generic, Protocol, TypeVar
import pandas as pd
_DataFrameBound = TypeVar("_DataFrameBound", bound=pd.DataFrame, covariant=True)
class _Method(Protocol[_DataFrameBound]):
def __call__(self, dataframe: pd.DataFrame) -> _DataFrameBound:
...
@dataclass
class MyClass(Generic[_DataFrameBound]):
_method: _Method[_DataFrameBound]
@dataclass
class MyClassDataFrame(MyClass[pd.DataFrame]):
...
def function(dataframe: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame()
my_class = MyClassDataFrame(function)
is failing with
error: Argument 1 to "MyClassDataFrame" has incompatible type "Callable[[DataFrame], DataFrame]"; expected "_Method[_DataFrameBound]" [arg-type]
and Pyright see it as a valid code so I think it should be seen as valid by mypy.
- Mypy version used:
0.931
- Mypy command-line flags:
poetry run mypy --no-warn-unused-ignores --show-error-codes
- Mypy configuration options from
mypy.ini
(and other config files):strict = true
- Python version used:
3.8.10
- Operating system and version: Ubuntu 21.10