Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 1, 2025 14:26
Show Gist options
  • Save mypy-play/5f8fe155f983bdb6950f422aee9cd612 to your computer and use it in GitHub Desktop.
Save mypy-play/5f8fe155f983bdb6950f422aee9cd612 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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