request.py 576 B

12345678910111213141516171819202122232425
  1. from abc import abstractmethod
  2. from dataclasses import dataclass
  3. @dataclass
  4. class AdapterRequest:
  5. """
  6. Base class for adapter requests.
  7. """
  8. @property
  9. @abstractmethod
  10. def adapter_id(self):
  11. ...
  12. def __post_init__(self):
  13. if self.adapter_id < 1:
  14. raise ValueError(f"id must be > 0, got {self.adapter_id}")
  15. def __eq__(self, value: object) -> bool:
  16. return isinstance(
  17. value, self.__class__) and self.adapter_id == value.adapter_id
  18. def __hash__(self) -> int:
  19. return hash(self.adapter_id)