From 443bfee16d0fec0be6689155fd0628aa0891eb8e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:33:39 +0100 Subject: [PATCH] Replace partial annotations (#114177) --- homeassistant/components/mqtt/mixins.py | 18 +++++++++++++----- homeassistant/util/dt.py | 2 +- tests/components/mqtt/test_init.py | 7 ------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index 42ad807d2f1..aa0ca3f8585 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -30,7 +30,7 @@ from homeassistant.const import ( CONF_UNIQUE_ID, CONF_VALUE_TEMPLATE, ) -from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback +from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import ( config_validation as cv, device_registry as dr, @@ -278,8 +278,8 @@ def async_handle_schema_error( async def _async_discover( hass: HomeAssistant, domain: str, - setup: partial[CALLBACK_TYPE] | None, - async_setup: partial[Coroutine[Any, Any, None]] | None, + setup: Callable[[MQTTDiscoveryPayload], None] | None, + async_setup: Callable[[MQTTDiscoveryPayload], Coroutine[Any, Any, None]] | None, discovery_payload: MQTTDiscoveryPayload, ) -> None: """Discover and add an MQTT entity, automation or tag. @@ -314,10 +314,18 @@ async def _async_discover( raise +class _SetupNonEntityHelperCallbackProtocol(Protocol): # pragma: no cover + """Callback protocol for async_setup in async_setup_non_entity_entry_helper.""" + + async def __call__( + self, config: ConfigType, discovery_data: DiscoveryInfoType + ) -> None: ... + + async def async_setup_non_entity_entry_helper( hass: HomeAssistant, domain: str, - async_setup: partial[Coroutine[Any, Any, None]], + async_setup: _SetupNonEntityHelperCallbackProtocol, discovery_schema: vol.Schema, ) -> None: """Set up automation or tag creation dynamically through MQTT discovery.""" @@ -327,7 +335,7 @@ async def async_setup_non_entity_entry_helper( discovery_payload: MQTTDiscoveryPayload, ) -> None: """Set up an MQTT entity, automation or tag from discovery.""" - config: DiscoveryInfoType = discovery_schema(discovery_payload) + config: ConfigType = discovery_schema(discovery_payload) await async_setup(config, discovery_data=discovery_payload.discovery_data) mqtt_data.reload_dispatchers.append( diff --git a/homeassistant/util/dt.py b/homeassistant/util/dt.py index 39976cce5f7..e85a302f371 100644 --- a/homeassistant/util/dt.py +++ b/homeassistant/util/dt.py @@ -100,7 +100,7 @@ def get_time_zone(time_zone_str: str) -> dt.tzinfo | None: # We use a partial here since it is implemented in native code # and avoids the global lookup of UTC -utcnow: partial[dt.datetime] = partial(dt.datetime.now, UTC) +utcnow = partial(dt.datetime.now, UTC) utcnow.__doc__ = "Get now in UTC time." diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index a9f2ba4354b..3e444e8d4c8 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -3,7 +3,6 @@ import asyncio from copy import deepcopy from datetime import datetime, timedelta -from functools import partial import json import ssl from typing import Any, TypedDict @@ -84,12 +83,6 @@ class _DebugInfo(TypedDict): config: _DebugDeviceInfo -class RecordCallsPartial(partial[Any]): - """Wrapper class for partial.""" - - __name__ = "RecordCallPartialTest" - - @pytest.fixture(autouse=True) def mock_storage(hass_storage: dict[str, Any]) -> None: """Autouse hass_storage for the TestCase tests."""