Skip to content

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

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

Closed
Fatal1ty opened this issue Aug 16, 2021 · 1 comment
Closed
Labels
bug mypy got something wrong topic-dataclasses topic-inheritance Inheritance and incompatible overrides

Comments

@Fatal1ty
Copy link

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
@ilevkivskyi
Copy link
Member

FWIW this works correctly on the current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-dataclasses topic-inheritance Inheritance and incompatible overrides
Projects
None yet
Development

No branches or pull requests

3 participants