Add an item to the registry with the given name and priority. Arguments: item: The item being registered. name: A string used to reference the item. priority: An integer or float used to sort against all items. If an item is registered w
(self, item: _T, name: str, priority: float)
| 363 | raise ValueError('No item named "{}" exists.'.format(name)) |
| 364 | |
| 365 | def register(self, item: _T, name: str, priority: float) -> None: |
| 366 | """ |
| 367 | Add an item to the registry with the given name and priority. |
| 368 | |
| 369 | Arguments: |
| 370 | item: The item being registered. |
| 371 | name: A string used to reference the item. |
| 372 | priority: An integer or float used to sort against all items. |
| 373 | |
| 374 | If an item is registered with a "name" which already exists, the |
| 375 | existing item is replaced with the new item. Treat carefully as the |
| 376 | old item is lost with no way to recover it. The new item will be |
| 377 | sorted according to its priority and will **not** retain the position |
| 378 | of the old item. |
| 379 | """ |
| 380 | if name in self: |
| 381 | # Remove existing item of same name first |
| 382 | self.deregister(name) |
| 383 | self._is_sorted = False |
| 384 | self._data[name] = item |
| 385 | self._priority.append(_PriorityItem(name, priority)) |
| 386 | |
| 387 | def deregister(self, name: str, strict: bool = True) -> None: |
| 388 | """ |