Home Assistant Unofficial Reference 2024.12.1
decorator.py
Go to the documentation of this file.
1 """Decorator utility functions."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable, Hashable
6 from typing import Any
7 
8 
9 class Registry[_KT: Hashable, _VT: Callable[..., Any]](dict[_KT, _VT]):
10  """Registry of items."""
11 
12  def register(self, name: _KT) -> Callable[[_VT], _VT]:
13  """Return decorator to register item with a specific name."""
14 
15  def decorator(func: _VT) -> _VT:
16  """Register decorated function."""
17  self[name] = func
18  return func
19 
20  return decorator
Callable[[_VT], _VT] register(self, _KT name)
Definition: decorator.py:12