Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with generic Protocol #12183

Closed
bloussou opened this issue Feb 15, 2022 · 2 comments
Closed

Issue with generic Protocol #12183

bloussou opened this issue Feb 15, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@bloussou
Copy link

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
@bloussou bloussou added the bug mypy got something wrong label Feb 15, 2022
@bloussou
Copy link
Author

Related pyright discussion : microsoft/pyright#3090

@hauntsaninja
Copy link
Collaborator

Thanks, I think this got fixed a while back, in 0.950 from #12656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants