exceptions.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # SPDX-License-Identifier: MIT
  2. from __future__ import absolute_import, division, print_function
  3. class FrozenError(AttributeError):
  4. """
  5. A frozen/immutable instance or attribute have been attempted to be
  6. modified.
  7. It mirrors the behavior of ``namedtuples`` by using the same error message
  8. and subclassing `AttributeError`.
  9. .. versionadded:: 20.1.0
  10. """
  11. msg = "can't set attribute"
  12. args = [msg]
  13. class FrozenInstanceError(FrozenError):
  14. """
  15. A frozen instance has been attempted to be modified.
  16. .. versionadded:: 16.1.0
  17. """
  18. class FrozenAttributeError(FrozenError):
  19. """
  20. A frozen attribute has been attempted to be modified.
  21. .. versionadded:: 20.1.0
  22. """
  23. class AttrsAttributeNotFoundError(ValueError):
  24. """
  25. An ``attrs`` function couldn't find an attribute that the user asked for.
  26. .. versionadded:: 16.2.0
  27. """
  28. class NotAnAttrsClassError(ValueError):
  29. """
  30. A non-``attrs`` class has been passed into an ``attrs`` function.
  31. .. versionadded:: 16.2.0
  32. """
  33. class DefaultAlreadySetError(RuntimeError):
  34. """
  35. A default has been set using ``attr.ib()`` and is attempted to be reset
  36. using the decorator.
  37. .. versionadded:: 17.1.0
  38. """
  39. class UnannotatedAttributeError(RuntimeError):
  40. """
  41. A class with ``auto_attribs=True`` has an ``attr.ib()`` without a type
  42. annotation.
  43. .. versionadded:: 17.3.0
  44. """
  45. class PythonTooOldError(RuntimeError):
  46. """
  47. It was attempted to use an ``attrs`` feature that requires a newer Python
  48. version.
  49. .. versionadded:: 18.2.0
  50. """
  51. class NotCallableError(TypeError):
  52. """
  53. A ``attr.ib()`` requiring a callable has been set with a value
  54. that is not callable.
  55. .. versionadded:: 19.2.0
  56. """
  57. def __init__(self, msg, value):
  58. super(TypeError, self).__init__(msg, value)
  59. self.msg = msg
  60. self.value = value
  61. def __str__(self):
  62. return str(self.msg)