exceptions.py 1.9 KB

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