Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created April 5, 2023 09:32
Embed
What would you like to do?
Shared via mypy Playground
from typing import TypeVar, Generic
from abc import abstractmethod, ABC
F = TypeVar("F")
class DatumGS(Generic[F]):
def __init__(self, key: str):
self.key = key
@abstractmethod
def get(self) -> F:
raise NotImplementedError
class DatumStr(DatumGS[str | None]):
def get(self) -> str | None:
return "hello"
D = TypeVar("D", bound="DatumGS")
class Wrapper(ABC):
datum: D[F]
@classmethod
@abstractmethod
def collect(cls) -> F:
raise NotImplementedError
@classmethod
def get(cls) -> F:
return cls.datum.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment