A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/mypy/issues/1246 below:

__init__ of subclass of a Generic class uses the generic type instead of the specified one · Issue #1246 · python/mypy · GitHub

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"

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4