Created
April 25, 2024 08:18
-
-
Save mypy-play/d8c92acf5b28281db6a1f63136f3993f 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
from typing import TypeVar, Generic, Any, cast | |
from abc import abstractmethod, ABC | |
_TP = TypeVar("_TP", bound=tuple[Any, ...]) | |
_TM = TypeVar("_TM") | |
class Select(Generic[_TP]): | |
pass | |
class Base: | |
pass | |
class Other(Base): | |
pass | |
ModelType = TypeVar("ModelType", bound=Base) | |
class DBRepository(ABC, Generic[ModelType]): | |
T = TypeVar("T", Select[tuple[ModelType]], Select[tuple[int]]) | |
@abstractmethod | |
def func(self, arg: T) -> T: | |
pass | |
class SubDBRepository(DBRepository[Other]): | |
def func(self, arg: Select[tuple[int]]) -> Select[tuple[int]]: | |
return cast(Select[tuple[int]], Select()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment