from typing import Generic, TypeVar T = TypeVar("T", covariant=True) class Foo(Generic[T]): def __init__(self, value: T) -> None: self.foo = value
here, T is used in both an in and out position as the value can be modified as well.
jailbreak:
objects = Foo[object](None) ints = Foo[int](1) def do_thing(value: Foo[object]) -> None: value.foo = "asdf" do_thing(ints) if TYPE_CHECKING: reveal_type(ints.foo) # int print(ints.foo) # "asdf" (hacked!!!!!!)
playground
Thanks, I think this is basically just a special case of #3208
Posted a comment in that issue, so if we ever do something about that we will also do something about this
Activity
hauntsaninja commented on Feb 2, 2023
Thanks, I think this is basically just a special case of #3208
hauntsaninja commented on Feb 2, 2023
Posted a comment in that issue, so if we ever do something about that we will also do something about this