| 11 | |
| 12 | |
| 13 | class SideEffect(CellLifecycleItem): |
| 14 | def __init__(self, key: str | bytes) -> None: |
| 15 | self._key = key |
| 16 | |
| 17 | @property |
| 18 | def key(self) -> bytes: |
| 19 | assert self._key is not None |
| 20 | if isinstance(self._key, bytes): |
| 21 | return self._key |
| 22 | return self._key.encode("utf-8") |
| 23 | |
| 24 | @property |
| 25 | def hash(self) -> bytes: |
| 26 | """Hash the lookup to a consistent size.""" |
| 27 | return hashlib.sha256(self.key).digest() |
| 28 | |
| 29 | def create(self, context: RuntimeContext | None) -> None: |
| 30 | """NoOp for side effect. |
| 31 | Typically hook to expose the object to the context, but the existence of |
| 32 | the object is enough for side effect tracking. |
| 33 | """ |
| 34 | del context |
| 35 | |
| 36 | def dispose(self, context: RuntimeContext, deletion: bool) -> bool: |
| 37 | """Clean up and mark the object for deletion""" |
| 38 | # Side effects can always be disposed since they are just a cell level |
| 39 | # marker that some event has occurred. |
| 40 | del context |
| 41 | del deletion |
| 42 | return True |
| 43 | |
| 44 | |
| 45 | class CellHash(CellLifecycleItem): |
no outgoing calls
no test coverage detected
searching dependent graphs…