Created
September 18, 2019 16:46
-
-
Save hackaugusto/5fb51b8a5e609757b82a36f644ec6f7e to your computer and use it in GitHub Desktop.
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, cast | |
| from typing_extensions import Literal | |
| T = TypeVar("T") | |
| class A(Generic[T]): | |
| def f1(self: "A[Literal[1]]") -> "A[Literal[2]]": | |
| return cast(A[Literal[2]], self) | |
| def f2(self: "A[Literal[2]]") -> "A[Literal[3]]": | |
| return cast(A[Literal[3]], self) | |
| a: A[Literal[1]] = A() | |
| a.f2().f1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment