Created
May 24, 2024 14:50
-
-
Save mypy-play/929aee66d6f65096049c0fc1abca6940 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains 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
# https://peps.python.org/pep-0646/ | |
from typing import Generic, Tuple, List, TypeVarTuple, Unpack | |
class A: | |
... | |
class B(A): | |
... | |
class C(A): | |
def __init__(self, value=1): | |
self.value = value | |
Ts = TypeVarTuple('Ts') | |
class Test(Generic[Unpack[Ts]]): | |
def __init__(self, *content: Unpack[Ts]): | |
self.content: List[Tuple[Unpack[Ts]]] = [content] | |
def call(self, *values: Unpack[Ts]): | |
self.content.append(values) | |
t2: Test[B, C] | |
t2 = Test(B(), C()) | |
t2.call(B(), C()) | |
t2.call(C(), C()) | |
t2.call(C()) | |
t3: Test[B, C] = Test((C(), C())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment