_attrs.py 791 B

12345678910111213141516171819202122232425262728293031
  1. from __future__ import annotations
  2. from typing import NoReturn, TypeVar
  3. from attrs import define as _define, frozen as _frozen
  4. _T = TypeVar("_T")
  5. def define(cls: type[_T]) -> type[_T]: # pragma: no cover
  6. cls.__init_subclass__ = _do_not_subclass
  7. return _define(cls)
  8. def frozen(cls: type[_T]) -> type[_T]:
  9. cls.__init_subclass__ = _do_not_subclass
  10. return _frozen(cls)
  11. class UnsupportedSubclassing(Exception):
  12. def __str__(self):
  13. return (
  14. "Subclassing is not part of referencing's public API. "
  15. "If no other suitable API exists for what you're trying to do, "
  16. "feel free to file an issue asking for one."
  17. )
  18. @staticmethod
  19. def _do_not_subclass() -> NoReturn: # pragma: no cover
  20. raise UnsupportedSubclassing()