Skip to content

False positive error "incompatible type" calling super() on a generic class with TypeVar constraints #14774

@leandro-lucarella-frequenz

Description

Reduced test case (mypy-playground):

from typing import Generic, TypeVar

T = TypeVar("T", float, int)


class C(Generic[T]):
    def __init__(self, i: T) -> None:
        self.i: T = i


class B(C[T]):
    def __init__(self, i: T) -> None:
        super().__init__(i)
main.py: note: In member "__init__" of class "B":
main.py:13:26: error: Argument 1 to "__init__" of "C" has incompatible type "float"; expected "T"  [arg-type]
main.py:13:26: error: Argument 1 to "__init__" of "C" has incompatible type "int"; expected "T"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Originally posted by @leandro-lucarella-frequenz in #13566 (comment) (this is a very similar issue but not exactly the same)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions