Patch a callback output value Act like a proxy of the output prop value on the frontend. Supported prop types: Dictionaries and lists.
| 16 | |
| 17 | |
| 18 | class Patch: |
| 19 | """ |
| 20 | Patch a callback output value |
| 21 | |
| 22 | Act like a proxy of the output prop value on the frontend. |
| 23 | |
| 24 | Supported prop types: Dictionaries and lists. |
| 25 | """ |
| 26 | |
| 27 | def __init__( |
| 28 | self, |
| 29 | location: Optional[List[_KeyType]] = None, |
| 30 | parent: Optional["Patch"] = None, |
| 31 | ): |
| 32 | if location is not None: |
| 33 | self._location: List[_KeyType] = location |
| 34 | else: |
| 35 | # pylint: disable=consider-using-ternary |
| 36 | self._location = (parent and parent._location) or [] |
| 37 | if parent is not None: |
| 38 | self._operations: List[Dict[str, Any]] = parent._operations |
| 39 | else: |
| 40 | self._operations = [] |
| 41 | |
| 42 | def __getstate__(self): |
| 43 | return vars(self) |
| 44 | |
| 45 | def __setstate__(self, state): |
| 46 | vars(self).update(state) |
| 47 | |
| 48 | def __getitem__(self, item: _KeyType) -> "Patch": |
| 49 | validate_slice(item) |
| 50 | return Patch(location=self._location + [item], parent=self) |
| 51 | |
| 52 | def __getattr__(self, item: _KeyType) -> "Patch": |
| 53 | if item == "tolist": |
| 54 | # to_json fix |
| 55 | raise AttributeError |
| 56 | if item == "_location": |
| 57 | return self._location # type: ignore |
| 58 | if item == "_operations": |
| 59 | return self._operations # type: ignore |
| 60 | return self.__getitem__(item) |
| 61 | |
| 62 | def __setattr__(self, key: _KeyType, value: Any): |
| 63 | if key in ("_location", "_operations"): |
| 64 | self.__dict__[str(key)] = value |
| 65 | else: |
| 66 | self.__setitem__(key, value) |
| 67 | |
| 68 | def __delattr__(self, item: _KeyType): |
| 69 | self.__delitem__(item) |
| 70 | |
| 71 | def __setitem__(self, key: _KeyType, value: Any): |
| 72 | validate_slice(key) |
| 73 | if value is _noop: |
| 74 | # The += set themselves. |
| 75 | return |
no outgoing calls
searching dependent graphs…