Skip to content

Instantly share code, notes, and snippets.

@orsinium
Last active March 30, 2022 07:19
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 orsinium/ad4d7cd4203b00e37d20e6ad8ab0dd22 to your computer and use it in GitHub Desktop.
Save orsinium/ad4d7cd4203b00e37d20e6ad8ab0dd22 to your computer and use it in GitHub Desktop.
from __future__ import annotations
from typing import Generic, TypeVar
T = TypeVar("T")
# ABC
class DatabaseProvider:
pass
class StorageProvider:
pass
class Connector(Generic[T]):
def connect(self) -> T:
pass
# Implementations
class GoogleProvider(DatabaseProvider, StorageProvider):
pass
class GoogleConnector(Connector[GoogleProvider]):
def connect(self) -> GoogleProvider:
return GoogleProvider()
# Incompatible types in assignment (expression has type "GoogleConnector", variable has type "Connector[DatabaseProvider]")
_: Connector[DatabaseProvider] = GoogleConnector()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment