Created
February 27, 2024 08:28
-
-
Save mypy-play/40d62fe7a0fc28bf68bd9d156ba77c5b 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
| 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