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

Incorrect mypy behaviour when inheriting a generic with List[T] field #10986

Open
Fatal1ty opened this issue Aug 16, 2021 · 0 comments
Open

Incorrect mypy behaviour when inheriting a generic with List[T] field #10986

Fatal1ty opened this issue Aug 16, 2021 · 0 comments
Labels
bug topic-dataclasses topic-inheritance

Comments

@Fatal1ty
Copy link

@Fatal1ty Fatal1ty commented Aug 16, 2021

I have the following sample of code:

from dataclasses import dataclass
from typing import Generic, List, TypeVar


T = TypeVar('T', int, str)


@dataclass
class A(Generic[T]):
    x: List[T]


@dataclass
class B(A[int]):
    pass


B(x=[1])  # error: List item 0 has incompatible type "int"; expected "T"

mypy 0.910 gives error: List item 0 has incompatible type "int"; expected "T" that is not what I expected since I declared x as List[int] with generic inheritance.

  • Mypy version used: 0.910
  • Python version used: 3.9.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug topic-dataclasses topic-inheritance
Projects
None yet
Development

No branches or pull requests

2 participants