Skip to content

__init__ of subclass of a Generic class uses the generic type instead of the specified one #1246

@alexsydell

Description

@alexsydell

Code to repro:

#!/usr/bin/env python
from typing import Generic, TypeVar

T = TypeVar("T")

class Test(Generic[T]):

    def __init__(self, a):
        # type: (T) -> None
        self.a = a

class StrTest(Test[str]):
    pass

s = StrTest("str1")

I would expect there to be no error here, but mypy outputs the following:

test.py:15: error: Argument 1 to "StrTest" has incompatible type "str"; expected "T"

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions