Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 24, 2024 14:50
Show Gist options
  • Save mypy-play/929aee66d6f65096049c0fc1abca6940 to your computer and use it in GitHub Desktop.
Save mypy-play/929aee66d6f65096049c0fc1abca6940 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
# 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