Open
Description
This currently passes, but the code is unsafe:
from typing import TypeVar, Generic
T = TypeVar('T')
class Base(Generic[T]):
def __init__(self, item: T) -> None:
self.item = item
def foo(self) -> None:
pass
class Sub(Base[T]):
def foo(self: Sub[str]) -> None:
self.item + 'no'
# This is why the above is unsafe.
a: Base[int] = Sub(0)
a.foo()
On one hand it is a very rare situation, on the other hand in view of making explicit self-types a more "official" feature (see #7860) we might want to fix this.
Also it would be great to fix this in a consistent way, so that the fix also works for same issue with multiple inheritance without code duplication (see #7724).