Created
May 3, 2025 10:56
-
-
Save mypy-play/36ace5d416f05fd648f7d7a4147f87f4 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Generic, TypeVar | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) | |
class Foo2(Foo[T]): | |
def print(self, t: T): | |
if t == self.t: | |
print("equal") | |
else: | |
Foo.print(self, t) | |
check_equal: bool = ... | |
printer = Foo2 if check_equal else Foo | |
reveal_type(printer) | |
a = printer(3) | |
a.print(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment