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

Unclear message if named tuple is not compatible with protocol #7224

Open
JukkaL opened this issue Jul 16, 2019 · 3 comments
Open

Unclear message if named tuple is not compatible with protocol #7224

JukkaL opened this issue Jul 16, 2019 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 16, 2019

Mypy just says that class is not compatible with the bound when type checking this example:

from typing import Protocol, Generic, TypeVar, NamedTuple, List, Any

class Example(Protocol):
    sentence: List[str]

T = TypeVar('T', bound=Example)

class Dataset(Generic[T]):
    ...

class ConcreteExample(NamedTuple):
    sentence: List[str]
    others: Any

class ConcreteDataset(Dataset[ConcreteExample]):
    ...

Here's the error message:

t.py:15: error: Type argument "Tuple[builtins.list[builtins.str], Any, fallback=t.ConcreteExample]" of "Dataset" must be a subtype of "t.Example"

It would be better to also say that sentence in ConcreteExample is read-only, and maybe suggest making it a read-only property in the protocol.

Originally reported in #7212.

@jmehnle
Copy link

jmehnle commented Oct 7, 2020

I'm having this problem. I have a user-defined protocol, and mypy is complaining that a concrete class is not a subtype of the protocol, but it gives me zero hints on how the class deviates from the protocol. :(

@gvanrossum
Copy link
Member

@jmehnle Could you show the source code and the error message?

@hauntsaninja
Copy link
Collaborator

Similar to #8836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants