A decorator which can be used to observe Traits on a class. The handler passed to the decorator will be called with one ``change`` dict argument. The change dictionary at least holds a 'type' key and a 'name' key, corresponding respectively to the type of notification and the name o
(*names: Sentinel | str, type: str = "change")
| 1097 | |
| 1098 | |
| 1099 | def observe(*names: Sentinel | str, type: str = "change") -> ObserveHandler: |
| 1100 | """A decorator which can be used to observe Traits on a class. |
| 1101 | |
| 1102 | The handler passed to the decorator will be called with one ``change`` |
| 1103 | dict argument. The change dictionary at least holds a 'type' key and a |
| 1104 | 'name' key, corresponding respectively to the type of notification and the |
| 1105 | name of the attribute that triggered the notification. |
| 1106 | |
| 1107 | Other keys may be passed depending on the value of 'type'. In the case |
| 1108 | where type is 'change', we also have the following keys: |
| 1109 | * ``owner`` : the HasTraits instance |
| 1110 | * ``old`` : the old value of the modified trait attribute |
| 1111 | * ``new`` : the new value of the modified trait attribute |
| 1112 | * ``name`` : the name of the modified trait attribute. |
| 1113 | |
| 1114 | Parameters |
| 1115 | ---------- |
| 1116 | *names |
| 1117 | The str names of the Traits to observe on the object. |
| 1118 | type : str, kwarg-only |
| 1119 | The type of event to observe (e.g. 'change') |
| 1120 | """ |
| 1121 | if not names: |
| 1122 | raise TypeError("Please specify at least one trait name to observe.") |
| 1123 | for name in names: |
| 1124 | if name is not All and not isinstance(name, str): |
| 1125 | raise TypeError("trait names to observe must be strings or All, not %r" % name) |
| 1126 | return ObserveHandler(names, type=type) |
| 1127 | |
| 1128 | |
| 1129 | def observe_compat(func: FuncT) -> FuncT: |
nothing calls this directly
no test coverage detected
searching dependent graphs…