Raised when a container can not be unwrapped into a meaningful value.
| 7 | |
| 8 | |
| 9 | class UnwrapFailedError(Exception): |
| 10 | """Raised when a container can not be unwrapped into a meaningful value.""" |
| 11 | |
| 12 | __slots__ = ('halted_container',) |
| 13 | |
| 14 | def __init__(self, container: Unwrappable) -> None: |
| 15 | """ |
| 16 | Saves halted container in the inner state. |
| 17 | |
| 18 | So, this container can later be unpacked from this exception |
| 19 | and used as a regular value. |
| 20 | """ |
| 21 | super().__init__() |
| 22 | self.halted_container = container |
| 23 | |
| 24 | def __reduce__(self): # noqa: WPS603 |
| 25 | """Custom reduce method for pickle protocol. |
| 26 | |
| 27 | This helps properly reconstruct the exception during unpickling. |
| 28 | """ |
| 29 | return ( |
| 30 | self.__class__, # callable |
| 31 | (self.halted_container,), # args to callable |
| 32 | ) |
| 33 | |
| 34 | |
| 35 | class ImmutableStateError(AttributeError): |