From cdafbbe10f723adf6f8dc2a7db22a7b390d4e6bc Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:19:51 +0200 Subject: [PATCH] Rename bound TypeVars (#70975) --- homeassistant/components/dlna_dmr/media_player.py | 10 ++++++---- homeassistant/components/evil_genius_labs/util.py | 10 ++++++---- homeassistant/components/plugwise/util.py | 12 +++++++----- homeassistant/components/sonarr/sensor.py | 10 ++++++---- homeassistant/components/vlc_telnet/media_player.py | 8 ++++---- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/dlna_dmr/media_player.py b/homeassistant/components/dlna_dmr/media_player.py index 807a983983b..9a7eef4bf89 100644 --- a/homeassistant/components/dlna_dmr/media_player.py +++ b/homeassistant/components/dlna_dmr/media_player.py @@ -61,18 +61,20 @@ from .data import EventListenAddr, get_domain_data PARALLEL_UPDATES = 0 -_T = TypeVar("_T", bound="DlnaDmrEntity") +_DlnaDmrEntityT = TypeVar("_DlnaDmrEntityT", bound="DlnaDmrEntity") _R = TypeVar("_R") _P = ParamSpec("_P") def catch_request_errors( - func: Callable[Concatenate[_T, _P], Awaitable[_R]] -) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R | None]]: + func: Callable[Concatenate[_DlnaDmrEntityT, _P], Awaitable[_R]] +) -> Callable[Concatenate[_DlnaDmrEntityT, _P], Coroutine[Any, Any, _R | None]]: """Catch UpnpError errors.""" @functools.wraps(func) - async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R | None: + async def wrapper( + self: _DlnaDmrEntityT, *args: _P.args, **kwargs: _P.kwargs + ) -> _R | None: """Catch UpnpError errors and check availability before and after request.""" if not self.available: _LOGGER.warning( diff --git a/homeassistant/components/evil_genius_labs/util.py b/homeassistant/components/evil_genius_labs/util.py index 7cbcc821bfe..1071b953027 100644 --- a/homeassistant/components/evil_genius_labs/util.py +++ b/homeassistant/components/evil_genius_labs/util.py @@ -9,18 +9,20 @@ from typing_extensions import Concatenate, ParamSpec from . import EvilGeniusEntity -_T = TypeVar("_T", bound=EvilGeniusEntity) +_EvilGeniusEntityT = TypeVar("_EvilGeniusEntityT", bound=EvilGeniusEntity) _R = TypeVar("_R") _P = ParamSpec("_P") def update_when_done( - func: Callable[Concatenate[_T, _P], Awaitable[_R]] -) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]: + func: Callable[Concatenate[_EvilGeniusEntityT, _P], Awaitable[_R]] +) -> Callable[Concatenate[_EvilGeniusEntityT, _P], Coroutine[Any, Any, _R]]: """Decorate function to trigger update when function is done.""" @wraps(func) - async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R: + async def wrapper( + self: _EvilGeniusEntityT, *args: _P.args, **kwargs: _P.kwargs + ) -> _R: """Wrap function.""" result = await func(self, *args, **kwargs) await self.coordinator.async_request_refresh() diff --git a/homeassistant/components/plugwise/util.py b/homeassistant/components/plugwise/util.py index 769bfc4ecea..55d9c204dd3 100644 --- a/homeassistant/components/plugwise/util.py +++ b/homeassistant/components/plugwise/util.py @@ -9,21 +9,23 @@ from homeassistant.exceptions import HomeAssistantError from .entity import PlugwiseEntity -_P = ParamSpec("_P") +_PlugwiseEntityT = TypeVar("_PlugwiseEntityT", bound=PlugwiseEntity) _R = TypeVar("_R") -_T = TypeVar("_T", bound=PlugwiseEntity) +_P = ParamSpec("_P") def plugwise_command( - func: Callable[Concatenate[_T, _P], Awaitable[_R]] -) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]: + func: Callable[Concatenate[_PlugwiseEntityT, _P], Awaitable[_R]] +) -> Callable[Concatenate[_PlugwiseEntityT, _P], Coroutine[Any, Any, _R]]: """Decorate Plugwise calls that send commands/make changes to the device. A decorator that wraps the passed in function, catches Plugwise errors, and requests an coordinator update to update status of the devices asap. """ - async def handler(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R: + async def handler( + self: _PlugwiseEntityT, *args: _P.args, **kwargs: _P.kwargs + ) -> _R: try: return await func(self, *args, **kwargs) except PlugwiseException as error: diff --git a/homeassistant/components/sonarr/sensor.py b/homeassistant/components/sonarr/sensor.py index 1604f500ab9..c9a946758c5 100644 --- a/homeassistant/components/sonarr/sensor.py +++ b/homeassistant/components/sonarr/sensor.py @@ -76,7 +76,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), ) -_T = TypeVar("_T", bound="SonarrSensor") +_SonarrSensorT = TypeVar("_SonarrSensorT", bound="SonarrSensor") _P = ParamSpec("_P") @@ -109,8 +109,8 @@ async def async_setup_entry( def sonarr_exception_handler( - func: Callable[Concatenate[_T, _P], Awaitable[None]] -) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: + func: Callable[Concatenate[_SonarrSensorT, _P], Awaitable[None]] +) -> Callable[Concatenate[_SonarrSensorT, _P], Coroutine[Any, Any, None]]: """Decorate Sonarr calls to handle Sonarr exceptions. A decorator that wraps the passed in function, catches Sonarr errors, @@ -118,7 +118,9 @@ def sonarr_exception_handler( """ @wraps(func) - async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None: + async def wrapper( + self: _SonarrSensorT, *args: _P.args, **kwargs: _P.kwargs + ) -> None: try: await func(self, *args, **kwargs) self.last_update_success = True diff --git a/homeassistant/components/vlc_telnet/media_player.py b/homeassistant/components/vlc_telnet/media_player.py index c7009c6c14d..7a0a796f665 100644 --- a/homeassistant/components/vlc_telnet/media_player.py +++ b/homeassistant/components/vlc_telnet/media_player.py @@ -31,7 +31,7 @@ from .const import DATA_AVAILABLE, DATA_VLC, DEFAULT_NAME, DOMAIN, LOGGER MAX_VOLUME = 500 -_T = TypeVar("_T", bound="VlcDevice") +_VlcDeviceT = TypeVar("_VlcDeviceT", bound="VlcDevice") _P = ParamSpec("_P") @@ -48,12 +48,12 @@ async def async_setup_entry( def catch_vlc_errors( - func: Callable[Concatenate[_T, _P], Awaitable[None]] -) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]: + func: Callable[Concatenate[_VlcDeviceT, _P], Awaitable[None]] +) -> Callable[Concatenate[_VlcDeviceT, _P], Coroutine[Any, Any, None]]: """Catch VLC errors.""" @wraps(func) - async def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None: + async def wrapper(self: _VlcDeviceT, *args: _P.args, **kwargs: _P.kwargs) -> None: """Catch VLC errors and modify availability.""" try: await func(self, *args, **kwargs)