Created
May 1, 2025 14:26
-
-
Save mypy-play/5f8fe155f983bdb6950f422aee9cd612 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 * | |
class B(): | |
def f(self) -> Self: | |
return self | |
class C(B): | |
pass | |
class D(B): | |
pass | |
T = TypeVar( | |
"T", | |
C, | |
D, | |
) | |
def g( | |
b: T, | |
) -> T: | |
return b.f() | |
TBounded = TypeVar( | |
"TBounded", | |
bound=B | |
) | |
def g_bounded( | |
b: TBounded, | |
) -> TBounded: | |
return b.f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment