Skip to content

Instantly share code, notes, and snippets.

@hackaugusto
Created September 18, 2019 16:46
Show Gist options
  • Save hackaugusto/5fb51b8a5e609757b82a36f644ec6f7e to your computer and use it in GitHub Desktop.
Save hackaugusto/5fb51b8a5e609757b82a36f644ec6f7e to your computer and use it in GitHub Desktop.
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