Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2. from typing import *
  3.  
  4.  
  5. class Model:
  6.     pass
  7.  
  8.  
  9. class Context:
  10.     pass
  11.  
  12.  
  13. T = TypeVar('T', Context)
  14.  
  15.  
  16. class ContextProvider(ABC, Generic[T]):
  17.     @abstractmethod
  18.     def make_context(self) -> T:
  19.         pass
  20.  
  21.  
  22. class DatabaseWorker(ABC):
  23.     @abstractmethod
  24.     def perform_work(self,
  25.                      prepared_data: Dict[str, Any],
  26.                      context_provider: ContextProvider[Context]) -> Optional[List[Model]]:
  27.         pass
  28.  
  29.  
  30. class ConcreteContext(Context):
  31.     def __init__(self):
  32.         self.foo = 'foo'
  33.         self.bar = 'bar'
  34.  
  35.  
  36. C = TypeVar('C', ConcreteContext)
  37.  
  38.  
  39. class ConcreteContextProvider(ContextProvider, Generic[C]):
  40.     def make_context(self) -> C:
  41.         return ConcreteContext()
  42.  
  43.  
  44. class ConcreteDatabaseWorker(DatabaseWorker):
  45.     def perform_work(self,
  46.                      prepared_data: Dict[str, Any],
  47.                      context_provider: ContextProvider[ConcreteContext]) -> Optional[List[Model]]:
  48.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement