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