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
| 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