From dd22ee3dac8cd3514138b892918c2e22cbdc2c70 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 24 May 2024 15:05:53 +0200 Subject: [PATCH] Improve annotation styling (#118032) --- homeassistant/components/http/web_runner.py | 2 +- homeassistant/components/motioneye/__init__.py | 2 +- homeassistant/components/mysensors/__init__.py | 2 +- homeassistant/components/network/util.py | 2 +- homeassistant/components/nibe_heatpump/climate.py | 2 +- homeassistant/components/picnic/services.py | 2 +- homeassistant/components/ping/__init__.py | 2 +- homeassistant/components/recorder/pool.py | 4 +++- homeassistant/components/sonos/media.py | 2 +- homeassistant/components/ssdp/__init__.py | 4 ++-- homeassistant/components/subaru/sensor.py | 2 +- homeassistant/components/template/binary_sensor.py | 2 +- homeassistant/components/template/sensor.py | 2 +- homeassistant/components/template/template_entity.py | 2 +- homeassistant/components/tibber/sensor.py | 4 ++-- homeassistant/helpers/condition.py | 12 ++++++------ homeassistant/helpers/dispatcher.py | 2 +- homeassistant/helpers/event.py | 6 +++--- homeassistant/helpers/service.py | 4 ++-- homeassistant/helpers/start.py | 2 +- tests/components/anova/conftest.py | 4 +++- tests/components/config/test_device_registry.py | 2 +- tests/components/ruckus_unleashed/__init__.py | 4 +++- tests/components/uptimerobot/common.py | 4 ++-- 24 files changed, 41 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/http/web_runner.py b/homeassistant/components/http/web_runner.py index fcdfbc661a7..4ca39eaab0c 100644 --- a/homeassistant/components/http/web_runner.py +++ b/homeassistant/components/http/web_runner.py @@ -27,7 +27,7 @@ class HomeAssistantTCPSite(web.BaseSite): def __init__( self, runner: web.BaseRunner, - host: None | str | list[str], + host: str | list[str] | None, port: int, *, ssl_context: SSLContext | None = None, diff --git a/homeassistant/components/motioneye/__init__.py b/homeassistant/components/motioneye/__init__.py index 43869ef51de..6ec3092ab35 100644 --- a/homeassistant/components/motioneye/__init__.py +++ b/homeassistant/components/motioneye/__init__.py @@ -414,7 +414,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def handle_webhook( hass: HomeAssistant, webhook_id: str, request: Request -) -> None | Response: +) -> Response | None: """Handle webhook callback.""" try: diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py index 699190a087c..ed18b890a24 100644 --- a/homeassistant/components/mysensors/__init__.py +++ b/homeassistant/components/mysensors/__init__.py @@ -110,7 +110,7 @@ def setup_mysensors_platform( device_class: type[MySensorsChildEntity] | Mapping[SensorType, type[MySensorsChildEntity]], device_args: ( - None | tuple + tuple | None ) = None, # extra arguments that will be given to the entity constructor async_add_entities: Callable | None = None, ) -> list[MySensorsChildEntity] | None: diff --git a/homeassistant/components/network/util.py b/homeassistant/components/network/util.py index c891904b7e9..88f4c1f913e 100644 --- a/homeassistant/components/network/util.py +++ b/homeassistant/components/network/util.py @@ -85,7 +85,7 @@ def _reset_enabled_adapters(adapters: list[Adapter]) -> None: def _ifaddr_adapter_to_ha( - adapter: ifaddr.Adapter, next_hop_address: None | IPv4Address | IPv6Address + adapter: ifaddr.Adapter, next_hop_address: IPv4Address | IPv6Address | None ) -> Adapter: """Convert an ifaddr adapter to ha.""" ip_v4s: list[IPv4ConfiguredAddress] = [] diff --git a/homeassistant/components/nibe_heatpump/climate.py b/homeassistant/components/nibe_heatpump/climate.py index 2bea3f2b9a4..d933d5a5ab0 100644 --- a/homeassistant/components/nibe_heatpump/climate.py +++ b/homeassistant/components/nibe_heatpump/climate.py @@ -113,7 +113,7 @@ class NibeClimateEntity(CoordinatorEntity[Coordinator], ClimateEntity): self._coil_current = _get(climate.current) self._coil_setpoint_heat = _get(climate.setpoint_heat) - self._coil_setpoint_cool: None | Coil + self._coil_setpoint_cool: Coil | None try: self._coil_setpoint_cool = _get(climate.setpoint_cool) except CoilNotFoundException: diff --git a/homeassistant/components/picnic/services.py b/homeassistant/components/picnic/services.py index f820daee54b..c01fc00a29e 100644 --- a/homeassistant/components/picnic/services.py +++ b/homeassistant/components/picnic/services.py @@ -76,7 +76,7 @@ async def handle_add_product( ) -def product_search(api_client: PicnicAPI, product_name: str | None) -> None | str: +def product_search(api_client: PicnicAPI, product_name: str | None) -> str | None: """Query the api client for the product name.""" if product_name is None: return None diff --git a/homeassistant/components/ping/__init__.py b/homeassistant/components/ping/__init__.py index e75b36dc38d..f0297794f2a 100644 --- a/homeassistant/components/ping/__init__.py +++ b/homeassistant/components/ping/__init__.py @@ -83,7 +83,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -async def _can_use_icmp_lib_with_privilege() -> None | bool: +async def _can_use_icmp_lib_with_privilege() -> bool | None: """Verify we can create a raw socket.""" try: await async_ping("127.0.0.1", count=0, timeout=0, privileged=True) diff --git a/homeassistant/components/recorder/pool.py b/homeassistant/components/recorder/pool.py index 7bf08a459d7..dcb19ddf044 100644 --- a/homeassistant/components/recorder/pool.py +++ b/homeassistant/components/recorder/pool.py @@ -1,5 +1,7 @@ """A pool for sqlite connections.""" +from __future__ import annotations + import asyncio import logging import threading @@ -51,7 +53,7 @@ class RecorderPool(SingletonThreadPool, NullPool): self.recorder_and_worker_thread_ids = recorder_and_worker_thread_ids SingletonThreadPool.__init__(self, creator, **kw) - def recreate(self) -> "RecorderPool": + def recreate(self) -> RecorderPool: """Recreate the pool.""" self.logger.info("Pool recreating") return self.__class__( diff --git a/homeassistant/components/sonos/media.py b/homeassistant/components/sonos/media.py index 1f5432c440b..6e8c629560b 100644 --- a/homeassistant/components/sonos/media.py +++ b/homeassistant/components/sonos/media.py @@ -44,7 +44,7 @@ DURATION_SECONDS = "duration_in_s" POSITION_SECONDS = "position_in_s" -def _timespan_secs(timespan: str | None) -> None | int: +def _timespan_secs(timespan: str | None) -> int | None: """Parse a time-span into number of seconds.""" if timespan in UNAVAILABLE_VALUES: return None diff --git a/homeassistant/components/ssdp/__init__.py b/homeassistant/components/ssdp/__init__.py index 17c35179326..7ca2f3e9318 100644 --- a/homeassistant/components/ssdp/__init__.py +++ b/homeassistant/components/ssdp/__init__.py @@ -148,7 +148,7 @@ def _format_err(name: str, *args: Any) -> str: async def async_register_callback( hass: HomeAssistant, callback: Callable[[SsdpServiceInfo, SsdpChange], Coroutine[Any, Any, None] | None], - match_dict: None | dict[str, str] = None, + match_dict: dict[str, str] | None = None, ) -> Callable[[], None]: """Register to receive a callback on ssdp broadcast. @@ -317,7 +317,7 @@ class Scanner: return list(self._device_tracker.devices.values()) async def async_register_callback( - self, callback: SsdpHassJobCallback, match_dict: None | dict[str, str] = None + self, callback: SsdpHassJobCallback, match_dict: dict[str, str] | None = None ) -> Callable[[], None]: """Register a callback.""" if match_dict is None: diff --git a/homeassistant/components/subaru/sensor.py b/homeassistant/components/subaru/sensor.py index bbb00a758dd..50ed89ca045 100644 --- a/homeassistant/components/subaru/sensor.py +++ b/homeassistant/components/subaru/sensor.py @@ -205,7 +205,7 @@ class SubaruSensor( self._attr_unique_id = f"{self.vin}_{description.key}" @property - def native_value(self) -> None | int | float: + def native_value(self) -> int | float | None: """Return the state of the sensor.""" vehicle_data = self.coordinator.data[self.vin] current_value = vehicle_data[VEHICLE_STATUS].get(self.entity_description.key) diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index 654dad94867..920b2090c47 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -483,7 +483,7 @@ class AutoOffExtraStoredData(ExtraStoredData): def as_dict(self) -> dict[str, Any]: """Return a dict representation of additional data.""" - auto_off_time: datetime | None | dict[str, str] = self.auto_off_time + auto_off_time: datetime | dict[str, str] | None = self.auto_off_time if isinstance(auto_off_time, datetime): auto_off_time = { "__type": str(type(auto_off_time)), diff --git a/homeassistant/components/template/sensor.py b/homeassistant/components/template/sensor.py index a341fdd5f87..171a8667d8f 100644 --- a/homeassistant/components/template/sensor.py +++ b/homeassistant/components/template/sensor.py @@ -257,7 +257,7 @@ class SensorTemplate(TemplateEntity, SensorEntity): self._attr_device_class = config.get(CONF_DEVICE_CLASS) self._attr_state_class = config.get(CONF_STATE_CLASS) self._template: template.Template = config[CONF_STATE] - self._attr_last_reset_template: None | template.Template = config.get( + self._attr_last_reset_template: template.Template | None = config.get( ATTR_LAST_RESET ) if (object_id := config.get(CONF_OBJECT_ID)) is not None: diff --git a/homeassistant/components/template/template_entity.py b/homeassistant/components/template/template_entity.py index bed9ead7922..b5d2ab6fff3 100644 --- a/homeassistant/components/template/template_entity.py +++ b/homeassistant/components/template/template_entity.py @@ -189,7 +189,7 @@ class _TemplateAttribute: self, event: Event[EventStateChangedData] | None, template: Template, - last_result: str | None | TemplateError, + last_result: str | TemplateError | None, result: str | TemplateError, ) -> None: """Handle a template result event callback.""" diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index e1b4bfa873d..c2faeb98ef3 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -342,8 +342,8 @@ class TibberSensor(SensorEntity): self._home_name = tibber_home.info["viewer"]["home"]["address"].get( "address1", "" ) - self._device_name: None | str = None - self._model: None | str = None + self._device_name: str | None = None + self._model: str | None = None @property def device_info(self) -> DeviceInfo: diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 3959a2147bd..bda2f67d803 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -352,7 +352,7 @@ async def async_not_from_config( def numeric_state( hass: HomeAssistant, - entity: None | str | State, + entity: str | State | None, below: float | str | None = None, above: float | str | None = None, value_template: Template | None = None, @@ -373,7 +373,7 @@ def numeric_state( def async_numeric_state( hass: HomeAssistant, - entity: None | str | State, + entity: str | State | None, below: float | str | None = None, above: float | str | None = None, value_template: Template | None = None, @@ -545,7 +545,7 @@ def async_numeric_state_from_config(config: ConfigType) -> ConditionCheckerType: def state( hass: HomeAssistant, - entity: None | str | State, + entity: str | State | None, req_state: Any, for_period: timedelta | None = None, attribute: str | None = None, @@ -803,7 +803,7 @@ def time( hass: HomeAssistant, before: dt_time | str | None = None, after: dt_time | str | None = None, - weekday: None | str | Container[str] = None, + weekday: str | Container[str] | None = None, ) -> bool: """Test if local time condition matches. @@ -902,8 +902,8 @@ def time_from_config(config: ConfigType) -> ConditionCheckerType: def zone( hass: HomeAssistant, - zone_ent: None | str | State, - entity: None | str | State, + zone_ent: str | State | None, + entity: str | State | None, ) -> bool: """Test if zone-condition matches. diff --git a/homeassistant/helpers/dispatcher.py b/homeassistant/helpers/dispatcher.py index b8aa9112e76..8fc7270ed08 100644 --- a/homeassistant/helpers/dispatcher.py +++ b/homeassistant/helpers/dispatcher.py @@ -164,7 +164,7 @@ def _format_err[*_Ts]( def _generate_job[*_Ts]( signal: SignalType[*_Ts] | str, target: Callable[[*_Ts], Any] | Callable[..., Any] -) -> HassJob[..., None | Coroutine[Any, Any, None]]: +) -> HassJob[..., Coroutine[Any, Any, None] | None]: """Generate a HassJob for a signal and target.""" job_type = get_hassjob_callable_job_type(target) return HassJob( diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index b160c79a581..fd97afbcaaf 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -201,8 +201,8 @@ def async_track_state_change( action: Callable[ [str, State | None, State | None], Coroutine[Any, Any, None] | None ], - from_state: None | str | Iterable[str] = None, - to_state: None | str | Iterable[str] = None, + from_state: str | Iterable[str] | None = None, + to_state: str | Iterable[str] | None = None, ) -> CALLBACK_TYPE: """Track specific state changes. @@ -1866,7 +1866,7 @@ track_time_change = threaded_listener_factory(async_track_time_change) def process_state_match( - parameter: None | str | Iterable[str], invert: bool = False + parameter: str | Iterable[str] | None, invert: bool = False ) -> Callable[[str | None], bool]: """Convert parameter to function that matches input against parameter.""" if parameter is None or parameter == MATCH_ALL: diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index e7a69e5680f..d20cba8909f 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -833,7 +833,7 @@ def async_set_service_schema( def _get_permissible_entity_candidates( call: ServiceCall, entities: dict[str, Entity], - entity_perms: None | (Callable[[str, str], bool]), + entity_perms: Callable[[str, str], bool] | None, target_all_entities: bool, all_referenced: set[str] | None, ) -> list[Entity]: @@ -889,7 +889,7 @@ async def entity_service_call( Calls all platforms simultaneously. """ - entity_perms: None | (Callable[[str, str], bool]) = None + entity_perms: Callable[[str, str], bool] | None = None return_response = call.return_response if call.context.user_id: diff --git a/homeassistant/helpers/start.py b/homeassistant/helpers/start.py index 70664430582..099060e49ca 100644 --- a/homeassistant/helpers/start.py +++ b/homeassistant/helpers/start.py @@ -36,7 +36,7 @@ def _async_at_core_state( hass.async_run_hass_job(at_start_job, hass) return lambda: None - unsub: None | CALLBACK_TYPE = None + unsub: CALLBACK_TYPE | None = None @callback def _matched_event(event: Event) -> None: diff --git a/tests/components/anova/conftest.py b/tests/components/anova/conftest.py index c59aeb76cdd..92f3c8ce6a7 100644 --- a/tests/components/anova/conftest.py +++ b/tests/components/anova/conftest.py @@ -1,5 +1,7 @@ """Common fixtures for Anova.""" +from __future__ import annotations + import asyncio from dataclasses import dataclass import json @@ -40,7 +42,7 @@ class MockedAnovaWebsocketStream: """Initialize a Anova Websocket Stream that can be manipulated for tests.""" self.messages = messages - def __aiter__(self) -> "MockedAnovaWebsocketStream": + def __aiter__(self) -> MockedAnovaWebsocketStream: """Handle async iteration.""" return self diff --git a/tests/components/config/test_device_registry.py b/tests/components/config/test_device_registry.py index 1b7eff84472..3d80b38e8e1 100644 --- a/tests/components/config/test_device_registry.py +++ b/tests/components/config/test_device_registry.py @@ -146,7 +146,7 @@ async def test_update_device( client: MockHAClientWebSocket, device_registry: dr.DeviceRegistry, payload_key: str, - payload_value: str | None | dr.DeviceEntryDisabler, + payload_value: str | dr.DeviceEntryDisabler | None, ) -> None: """Test update entry.""" entry = MockConfigEntry(title=None) diff --git a/tests/components/ruckus_unleashed/__init__.py b/tests/components/ruckus_unleashed/__init__.py index cf510b87314..ccbf404cce0 100644 --- a/tests/components/ruckus_unleashed/__init__.py +++ b/tests/components/ruckus_unleashed/__init__.py @@ -1,5 +1,7 @@ """Tests for the Ruckus Unleashed integration.""" +from __future__ import annotations + from unittest.mock import AsyncMock, patch from aioruckus import AjaxSession, RuckusAjaxApi @@ -181,7 +183,7 @@ class RuckusAjaxApiPatchContext: def _patched_async_create( host: str, username: str, password: str - ) -> "AjaxSession": + ) -> AjaxSession: return AjaxSession(None, host, username, password) self.patchers.append( diff --git a/tests/components/uptimerobot/common.py b/tests/components/uptimerobot/common.py index c2d154cd967..01f003327c1 100644 --- a/tests/components/uptimerobot/common.py +++ b/tests/components/uptimerobot/common.py @@ -81,10 +81,10 @@ class MockApiResponseKey(str, Enum): def mock_uptimerobot_api_response( data: dict[str, Any] - | None | list[UptimeRobotMonitor] | UptimeRobotAccount - | UptimeRobotApiError = None, + | UptimeRobotApiError + | None = None, status: APIStatus = APIStatus.OK, key: MockApiResponseKey = MockApiResponseKey.MONITORS, ) -> UptimeRobotApiResponse: