Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created February 27, 2024 08:28
Show Gist options
  • Select an option

  • Save mypy-play/40d62fe7a0fc28bf68bd9d156ba77c5b to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/40d62fe7a0fc28bf68bd9d156ba77c5b to your computer and use it in GitHub Desktop.
Shared via mypy Playground
import typing
T = typing.TypeVar("T")
class Container(typing.Generic[T]):
def __init__(self, value : T) -> None:
self.value = value
class A(Container[int]):
pass
class B(Container[A]):
pass
def get(x: Container[T]) -> T:
return x.value
a = B(A(5))
reveal_type(a)
b = get(a)
reveal_type(b)
c1 = get(b)
reveal_type(c1)
# This is expected to match 'c1'
c2 = get(get(a))
reveal_type(c2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment