Last active
March 30, 2022 07:19
-
-
Save orsinium/ad4d7cd4203b00e37d20e6ad8ab0dd22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 __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