Expected MyPy errors when using Generic class but none given

Viewed 41

I run mypy on the following program but I get no error. It says: "Success: no issues found in 1 source file"

from typing import TypeVar, Generic

T = TypeVar('T')

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

    def get_val(self) -> T:
        return self.value

    def set_val(self, target_value: T) -> None:
        self.value = target_value


class MyClassInt(MyClass[int]):
    pass

def main():
    my_var = MyClassInt(value='six')
    my_var.set_val("str")

if __name__ == "__main__":
    main()

I would expect two errors. One when I call the MyClassInt constructor and one at my_var.set_val("str").

What am I missing? Any help is appreciated.

For what it's worth, PyCharm (2021.2.2) does give two warnings.

enter image description here

0 Answers
Related