Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created April 25, 2024 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mypy-play/83b3a530185da51adba775b76bf60d74 to your computer and use it in GitHub Desktop.
Save mypy-play/83b3a530185da51adba775b76bf60d74 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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