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