Closed
Description
This code doesn't produce any type errors, but will crash at runtime when calling len
with an int.
T = TypeVar('T')
class Box(Generic[T]):
def __init__(self, val: T) -> None:
self.val = val
def foo(self: 'Box[str]') -> 'int':
return len(self.val)
Box(1).foo()
Calling the foo
method like this does result in a type error
Box.foo(Box(1))