From 1a38d2089d0d4a162608b6c4d5a62f00f121154b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 10 Apr 2021 15:21:11 +0200 Subject: [PATCH] Bump python-typing-update to v0.3.3 (#48992) * Bump python-typing-update to 0.3.3 * Changes after update --- .pre-commit-config.yaml | 2 +- .../components/denonavr/config_flow.py | 22 ++++++++++--------- homeassistant/components/denonavr/receiver.py | 8 ++++--- .../components/kostal_plenticore/helper.py | 11 +++++----- .../components/kostal_plenticore/sensor.py | 18 ++++++++------- homeassistant/components/modbus/__init__.py | 6 +++-- tests/components/axis/conftest.py | 4 ++-- tests/components/climacell/test_weather.py | 6 +++-- tests/components/onewire/__init__.py | 7 +++--- 9 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97093bc8dbe..9ea2ea51348 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,7 +69,7 @@ repos: - id: prettier stages: [manual] - repo: https://github.com/cdce8p/python-typing-update - rev: v0.3.2 + rev: v0.3.3 hooks: # Run `python-typing-update` hook manually from time to time # to update python typing syntax. diff --git a/homeassistant/components/denonavr/config_flow.py b/homeassistant/components/denonavr/config_flow.py index f2c37d9fc75..adcd4e26b6f 100644 --- a/homeassistant/components/denonavr/config_flow.py +++ b/homeassistant/components/denonavr/config_flow.py @@ -1,6 +1,8 @@ """Config flow to configure Denon AVR receivers using their HTTP interface.""" +from __future__ import annotations + import logging -from typing import Any, Dict, Optional +from typing import Any from urllib.parse import urlparse import denonavr @@ -44,7 +46,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): """Init object.""" self.config_entry = config_entry - async def async_step_init(self, user_input: Optional[Dict[str, Any]] = None): + async def async_step_init(self, user_input: dict[str, Any] | None = None): """Manage the options.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) @@ -96,7 +98,7 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Get the options flow.""" return OptionsFlowHandler(config_entry) - async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None): + async def async_step_user(self, user_input: dict[str, Any] | None = None): """Handle a flow initialized by the user.""" errors = {} if user_input is not None: @@ -123,8 +125,8 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): ) async def async_step_select( - self, user_input: Optional[Dict[str, Any]] = None - ) -> Dict[str, Any]: + self, user_input: dict[str, Any] | None = None + ) -> dict[str, Any]: """Handle multiple receivers found.""" errors = {} if user_input is not None: @@ -144,8 +146,8 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): ) async def async_step_confirm( - self, user_input: Optional[Dict[str, Any]] = None - ) -> Dict[str, Any]: + self, user_input: dict[str, Any] | None = None + ) -> dict[str, Any]: """Allow the user to confirm adding the device.""" if user_input is not None: return await self.async_step_connect() @@ -154,8 +156,8 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): return self.async_show_form(step_id="confirm") async def async_step_connect( - self, user_input: Optional[Dict[str, Any]] = None - ) -> Dict[str, Any]: + self, user_input: dict[str, Any] | None = None + ) -> dict[str, Any]: """Connect to the receiver.""" connect_denonavr = ConnectDenonAVR( self.host, @@ -204,7 +206,7 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): }, ) - async def async_step_ssdp(self, discovery_info: Dict[str, Any]) -> Dict[str, Any]: + async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> dict[str, Any]: """Handle a discovered Denon AVR. This flow is triggered by the SSDP component. It will check if the diff --git a/homeassistant/components/denonavr/receiver.py b/homeassistant/components/denonavr/receiver.py index 31d91c0a9ba..8b50373799b 100644 --- a/homeassistant/components/denonavr/receiver.py +++ b/homeassistant/components/denonavr/receiver.py @@ -1,6 +1,8 @@ """Code to handle a DenonAVR receiver.""" +from __future__ import annotations + import logging -from typing import Callable, Optional +from typing import Callable from denonavr import DenonAVR @@ -18,7 +20,7 @@ class ConnectDenonAVR: zone2: bool, zone3: bool, async_client_getter: Callable, - entry_state: Optional[str] = None, + entry_state: str | None = None, ): """Initialize the class.""" self._async_client_getter = async_client_getter @@ -35,7 +37,7 @@ class ConnectDenonAVR: self._zones["Zone3"] = None @property - def receiver(self) -> Optional[DenonAVR]: + def receiver(self) -> DenonAVR | None: """Return the class containing all connections to the receiver.""" return self._receiver diff --git a/homeassistant/components/kostal_plenticore/helper.py b/homeassistant/components/kostal_plenticore/helper.py index 6f9cc4f5ee0..a78896a179d 100644 --- a/homeassistant/components/kostal_plenticore/helper.py +++ b/homeassistant/components/kostal_plenticore/helper.py @@ -1,9 +1,10 @@ """Code to handle the Plenticore API.""" +from __future__ import annotations + import asyncio from collections import defaultdict from datetime import datetime, timedelta import logging -from typing import Dict, Union from aiohttp.client_exceptions import ClientError from kostal.plenticore import PlenticoreApiClient, PlenticoreAuthenticationException @@ -151,7 +152,7 @@ class PlenticoreUpdateCoordinator(DataUpdateCoordinator): class ProcessDataUpdateCoordinator(PlenticoreUpdateCoordinator): """Implementation of PlenticoreUpdateCoordinator for process data.""" - async def _async_update_data(self) -> Dict[str, Dict[str, str]]: + async def _async_update_data(self) -> dict[str, dict[str, str]]: client = self._plenticore.client if not self._fetch or client is None: @@ -172,7 +173,7 @@ class ProcessDataUpdateCoordinator(PlenticoreUpdateCoordinator): class SettingDataUpdateCoordinator(PlenticoreUpdateCoordinator): """Implementation of PlenticoreUpdateCoordinator for settings data.""" - async def _async_update_data(self) -> Dict[str, Dict[str, str]]: + async def _async_update_data(self) -> dict[str, dict[str, str]]: client = self._plenticore.client if not self._fetch or client is None: @@ -223,7 +224,7 @@ class PlenticoreDataFormatter: return getattr(cls, name) @staticmethod - def format_round(state: str) -> Union[int, str]: + def format_round(state: str) -> int | str: """Return the given state value as rounded integer.""" try: return round(float(state)) @@ -231,7 +232,7 @@ class PlenticoreDataFormatter: return state @staticmethod - def format_energy(state: str) -> Union[float, str]: + def format_energy(state: str) -> float | str: """Return the given state value as energy value, scaled to kWh.""" try: return round(float(state) / 1000, 1) diff --git a/homeassistant/components/kostal_plenticore/sensor.py b/homeassistant/components/kostal_plenticore/sensor.py index 82b06c96a77..f9d25f65d90 100644 --- a/homeassistant/components/kostal_plenticore/sensor.py +++ b/homeassistant/components/kostal_plenticore/sensor.py @@ -1,7 +1,9 @@ """Platform for Kostal Plenticore sensors.""" +from __future__ import annotations + from datetime import timedelta import logging -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry @@ -109,9 +111,9 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): module_id: str, data_id: str, sensor_name: str, - sensor_data: Dict[str, Any], + sensor_data: dict[str, Any], formatter: Callable[[str], Any], - device_info: Dict[str, Any], + device_info: dict[str, Any], ): """Create a new Sensor Entity for Plenticore process data.""" super().__init__(coordinator) @@ -147,7 +149,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): await super().async_will_remove_from_hass() @property - def device_info(self) -> Dict[str, Any]: + def device_info(self) -> dict[str, Any]: """Return the device info.""" return self._device_info @@ -162,17 +164,17 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): return f"{self.platform_name} {self._sensor_name}" @property - def unit_of_measurement(self) -> Optional[str]: + def unit_of_measurement(self) -> str | None: """Return the unit of this Sensor Entity or None.""" return self._sensor_data.get(ATTR_UNIT_OF_MEASUREMENT) @property - def icon(self) -> Optional[str]: + def icon(self) -> str | None: """Return the icon name of this Sensor Entity or None.""" return self._sensor_data.get(ATTR_ICON) @property - def device_class(self) -> Optional[str]: + def device_class(self) -> str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return self._sensor_data.get(ATTR_DEVICE_CLASS) @@ -182,7 +184,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): return self._sensor_data.get(ATTR_ENABLED_DEFAULT, False) @property - def state(self) -> Optional[Any]: + def state(self) -> Any | None: """Return the state of the sensor.""" if self.coordinator.data is None: # None is translated to STATE_UNKNOWN diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index a4e0c21ec5f..2defb32393d 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -1,5 +1,7 @@ """Support for Modbus.""" -from typing import Any, Union +from __future__ import annotations + +from typing import Any import voluptuous as vol @@ -95,7 +97,7 @@ from .modbus import modbus_setup BASE_SCHEMA = vol.Schema({vol.Optional(CONF_NAME, default=DEFAULT_HUB): cv.string}) -def number(value: Any) -> Union[int, float]: +def number(value: Any) -> int | float: """Coerce a value to number without losing precision.""" if isinstance(value, int): return value diff --git a/tests/components/axis/conftest.py b/tests/components/axis/conftest.py index be448359366..c816277a3f4 100644 --- a/tests/components/axis/conftest.py +++ b/tests/components/axis/conftest.py @@ -1,6 +1,6 @@ """Axis conftest.""" +from __future__ import annotations -from typing import Optional from unittest.mock import patch from axis.rtsp import ( @@ -34,7 +34,7 @@ def mock_axis_rtspclient(): rtsp_client_mock.return_value.stop = stop_stream - def make_rtsp_call(data: Optional[dict] = None, state: str = ""): + def make_rtsp_call(data: dict | None = None, state: str = ""): """Generate a RTSP call.""" axis_streammanager_session_callback = rtsp_client_mock.call_args[0][4] diff --git a/tests/components/climacell/test_weather.py b/tests/components/climacell/test_weather.py index c49ad8b3c48..646c5cd114b 100644 --- a/tests/components/climacell/test_weather.py +++ b/tests/components/climacell/test_weather.py @@ -1,7 +1,9 @@ """Tests for Climacell weather entity.""" +from __future__ import annotations + from datetime import datetime import logging -from typing import Any, Dict +from typing import Any from unittest.mock import patch import pytest @@ -58,7 +60,7 @@ async def _enable_entity(hass: HomeAssistantType, entity_name: str) -> None: assert updated_entry.disabled is False -async def _setup(hass: HomeAssistantType, config: Dict[str, Any]) -> State: +async def _setup(hass: HomeAssistantType, config: dict[str, Any]) -> State: """Set up entry and return entity state.""" with patch( "homeassistant.util.dt.utcnow", diff --git a/tests/components/onewire/__init__.py b/tests/components/onewire/__init__.py index f133f89d5d6..fdc0c7fe12c 100644 --- a/tests/components/onewire/__init__.py +++ b/tests/components/onewire/__init__.py @@ -1,6 +1,7 @@ """Tests for 1-Wire integration.""" +from __future__ import annotations -from typing import Any, List, Tuple +from typing import Any from unittest.mock import patch from pyownet.protocol import ProtocolError @@ -129,8 +130,8 @@ def setup_owproxy_mock_devices(owproxy, domain, device_ids) -> None: def setup_sysbus_mock_devices( - domain: str, device_ids: List[str] -) -> Tuple[List[str], List[Any]]: + domain: str, device_ids: list[str] +) -> tuple[list[str], list[Any]]: """Set up mock for sysbus.""" glob_result = [] read_side_effect = []