Skip to content

Commit

Permalink
Improve roku error decorator typing (#70992)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Apr 28, 2022
1 parent cf90e34 commit 7649b5e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions homeassistant/components/roku/helpers.py
Expand Up @@ -13,7 +13,7 @@

_LOGGER = logging.getLogger(__name__)

_T = TypeVar("_T", bound=RokuEntity)
_RokuEntityT = TypeVar("_RokuEntityT", bound=RokuEntity)
_P = ParamSpec("_P")


Expand All @@ -25,14 +25,21 @@ def format_channel_name(channel_number: str, channel_name: str | None = None) ->
return channel_number


def roku_exception_handler(ignore_timeout: bool = False) -> Callable[..., Callable]:
def roku_exception_handler(
ignore_timeout: bool = False,
) -> Callable[
[Callable[Concatenate[_RokuEntityT, _P], Awaitable[Any]]],
Callable[Concatenate[_RokuEntityT, _P], Coroutine[Any, Any, None]],
]:
"""Decorate Roku calls to handle Roku exceptions."""

def decorator(
func: Callable[Concatenate[_T, _P], Awaitable[None]],
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
func: Callable[Concatenate[_RokuEntityT, _P], Awaitable[Any]],
) -> Callable[Concatenate[_RokuEntityT, _P], Coroutine[Any, Any, None]]:
@wraps(func)
async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None:
async def wrapper(
self: _RokuEntityT, *args: _P.args, **kwargs: _P.kwargs
) -> None:
try:
await func(self, *args, **kwargs)
except RokuConnectionTimeoutError as error:
Expand Down

0 comments on commit 7649b5e

Please sign in to comment.