Skip to content

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

Closed

Description

@Fatal1ty

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

Activity

  1. ilevkivskyi commented on Nov 16, 2022

    @ilevkivskyi
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions