daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top