Files
home-assistant-core/homeassistant/util/decorator.py
T
Andrey 140a874917 Add typing to homeassistant/*.py and homeassistant/util/ (#15569)
* Add typing to homeassistant/*.py and homeassistant/util/

* Fix wrong merge

* Restore iterable in OrderedSet

* Fix tests
2018-07-23 10:24:39 +02:00

17 lines
502 B
Python

"""Decorator utility functions."""
from typing import Callable, TypeVar
CALLABLE_T = TypeVar('CALLABLE_T', bound=Callable)
class Registry(dict):
"""Registry of items."""
def register(self, name: str) -> Callable[[CALLABLE_T], CALLABLE_T]:
"""Return decorator to register item with a specific name."""
def decorator(func: CALLABLE_T) -> CALLABLE_T:
"""Register decorated function."""
self[name] = func
return func
return decorator