Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- from typing import *
- class Model:
- pass
- class Context:
- pass
- T = TypeVar('T', Context)
- class ContextProvider(ABC, Generic[T]):
- @abstractmethod
- def make_context(self) -> T:
- pass
- class DatabaseWorker(ABC):
- @abstractmethod
- def perform_work(self,
- prepared_data: Dict[str, Any],
- context_provider: ContextProvider[Context]) -> Optional[List[Model]]:
- pass
- class ConcreteContext(Context):
- def __init__(self):
- self.foo = 'foo'
- self.bar = 'bar'
- C = TypeVar('C', ConcreteContext)
- class ConcreteContextProvider(ContextProvider, Generic[C]):
- def make_context(self) -> C:
- return ConcreteContext()
- class ConcreteDatabaseWorker(DatabaseWorker):
- def perform_work(self,
- prepared_data: Dict[str, Any],
- context_provider: ContextProvider[ConcreteContext]) -> Optional[List[Model]]:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement