From 07a3046d11d7e81b4f0ee8ca7f5c0b1560050c3e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 2 Feb 2023 12:49:01 +0100 Subject: [PATCH] Update pylint to 2.16.0 (#87083) --- homeassistant/components/fritz/common.py | 1 + homeassistant/components/gogogate2/common.py | 4 ++-- .../components/greeneye_monitor/sensor.py | 2 +- .../components/here_travel_time/coordinator.py | 4 ++-- homeassistant/components/icloud/__init__.py | 2 +- homeassistant/components/icloud/account.py | 2 +- homeassistant/components/insteon/light.py | 1 + homeassistant/components/litejet/trigger.py | 1 - homeassistant/components/philips_js/light.py | 15 ++++++++------- homeassistant/components/starline/config_flow.py | 1 + homeassistant/components/twitch/sensor.py | 8 +++++--- homeassistant/components/xiaomi_miio/light.py | 10 +++++----- homeassistant/helpers/config_entry_oauth2_flow.py | 4 ++-- pyproject.toml | 14 +++++++------- requirements_test.txt | 4 ++-- 15 files changed, 39 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index 89c85c77972..09103a0bcc8 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -429,6 +429,7 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator[None]): self.fritz_hosts.get_mesh_topology ) ): + # pylint: disable=broad-exception-raised raise Exception("Mesh supported but empty topology reported") except FritzActionError: self.mesh_role = MeshRoles.SLAVE diff --git a/homeassistant/components/gogogate2/common.py b/homeassistant/components/gogogate2/common.py index 3b72e85276c..d45a4fb44ec 100644 --- a/homeassistant/components/gogogate2/common.py +++ b/homeassistant/components/gogogate2/common.py @@ -4,7 +4,7 @@ from __future__ import annotations from collections.abc import Awaitable, Callable, Mapping from datetime import timedelta import logging -from typing import Any, NamedTuple, Union +from typing import Any, NamedTuple from ismartgate import ( AbstractGateApi, @@ -46,7 +46,7 @@ class StateData(NamedTuple): class DeviceDataUpdateCoordinator( - DataUpdateCoordinator[Union[GogoGate2InfoResponse, ISmartGateInfoResponse]] + DataUpdateCoordinator[GogoGate2InfoResponse | ISmartGateInfoResponse] ): """Manages polling for state changes from the device.""" diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index b4c62cd2bc1..c11a4168045 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -239,7 +239,7 @@ class PulseCounter(GEMSensor): return 3600 # Config schema should have ensured it is one of the above values - raise Exception( + raise RuntimeError( f"Invalid value for time unit: {self._time_unit}. Expected one of" f" {UnitOfTime.SECONDS}, {UnitOfTime.MINUTES}, or {UnitOfTime.HOURS}" ) diff --git a/homeassistant/components/here_travel_time/coordinator.py b/homeassistant/components/here_travel_time/coordinator.py index e76691253f9..ae8bfc34a42 100644 --- a/homeassistant/components/here_travel_time/coordinator.py +++ b/homeassistant/components/here_travel_time/coordinator.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import datetime, time, timedelta import logging -from typing import Any, Optional +from typing import Any import here_routing from here_routing import ( @@ -163,7 +163,7 @@ class HERERoutingDataUpdateCoordinator(DataUpdateCoordinator[HERETravelTimeData] class HERETransitDataUpdateCoordinator( - DataUpdateCoordinator[Optional[HERETravelTimeData]] + DataUpdateCoordinator[HERETravelTimeData | None] ): """HERETravelTime DataUpdateCoordinator.""" diff --git a/homeassistant/components/icloud/__init__.py b/homeassistant/components/icloud/__init__.py index 63802804f4d..010de4ec4ba 100644 --- a/homeassistant/components/icloud/__init__.py +++ b/homeassistant/components/icloud/__init__.py @@ -154,7 +154,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: icloud_account = account if icloud_account is None: - raise Exception( + raise ValueError( f"No iCloud account with username or name {account_identifier}" ) return icloud_account diff --git a/homeassistant/components/icloud/account.py b/homeassistant/components/icloud/account.py index 7dc0e0ec830..257bf536006 100644 --- a/homeassistant/components/icloud/account.py +++ b/homeassistant/components/icloud/account.py @@ -324,7 +324,7 @@ class IcloudAccount: if slugify(device.name.replace(" ", "", 99)) == name_slug: result.append(device) if not result: - raise Exception(f"No device with name {name}") + raise ValueError(f"No device with name {name}") return result @property diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 062a3f54d1b..579945e6f82 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -58,6 +58,7 @@ class InsteonDimmerEntity(InsteonEntity, LightEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Turn light on.""" + brightness: int | None = None if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS]) elif self._insteon_device_group.group == 1: diff --git a/homeassistant/components/litejet/trigger.py b/homeassistant/components/litejet/trigger.py index 502d84693c6..926ed69637f 100644 --- a/homeassistant/components/litejet/trigger.py +++ b/homeassistant/components/litejet/trigger.py @@ -92,7 +92,6 @@ async def async_attach_trigger( """Handle the release of the LiteJet switch's button.""" nonlocal cancel_pressed_more_than, pressed_time nonlocal held_less_than, held_more_than - # pylint: disable=not-callable if cancel_pressed_more_than is not None: cancel_pressed_more_than() cancel_pressed_more_than = None diff --git a/homeassistant/components/philips_js/light.py b/homeassistant/components/philips_js/light.py index c218c30347e..8df88ff923a 100644 --- a/homeassistant/components/philips_js/light.py +++ b/homeassistant/components/philips_js/light.py @@ -17,6 +17,7 @@ from homeassistant.components.light import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -287,11 +288,11 @@ class PhilipsTVLightEntity( } if not await self._tv.setAmbilightCached(data): - raise Exception("Failed to set ambilight color") + raise HomeAssistantError("Failed to set ambilight color") if effect.style != self._tv.ambilight_mode: if not await self._tv.setAmbilightMode(effect.style): - raise Exception("Failed to set ambilight mode") + raise HomeAssistantError("Failed to set ambilight mode") async def _set_ambilight_expert_config( self, effect: AmbilightEffect, hs_color: tuple[float, float], brightness: int @@ -325,7 +326,7 @@ class PhilipsTVLightEntity( config["tuning"] = 0 if not await self._tv.setAmbilightCurrentConfiguration(config): - raise Exception("Failed to set ambilight mode") + raise HomeAssistantError("Failed to set ambilight mode") async def _set_ambilight_config(self, effect: AmbilightEffect): """Set ambilight via current configuration.""" @@ -336,7 +337,7 @@ class PhilipsTVLightEntity( } if await self._tv.setAmbilightCurrentConfiguration(config) is False: - raise Exception("Failed to set ambilight mode") + raise HomeAssistantError("Failed to set ambilight mode") async def async_turn_on(self, **kwargs: Any) -> None: """Turn the bulb on.""" @@ -345,7 +346,7 @@ class PhilipsTVLightEntity( attr_effect = kwargs.get(ATTR_EFFECT, self.effect) if not self._tv.on: - raise Exception("TV is not available") + raise HomeAssistantError("TV is not available") effect = AmbilightEffect.from_str(attr_effect) @@ -383,10 +384,10 @@ class PhilipsTVLightEntity( """Turn of ambilight.""" if not self._tv.on: - raise Exception("TV is not available") + raise HomeAssistantError("TV is not available") if await self._tv.setAmbilightMode("internal") is False: - raise Exception("Failed to set ambilight mode") + raise HomeAssistantError("Failed to set ambilight mode") await self._set_ambilight_config(AmbilightEffect(EFFECT_MODE, "OFF", "")) diff --git a/homeassistant/components/starline/config_flow.py b/homeassistant/components/starline/config_flow.py index 25e01da4ee7..8a5aa494a5f 100644 --- a/homeassistant/components/starline/config_flow.py +++ b/homeassistant/components/starline/config_flow.py @@ -212,6 +212,7 @@ class StarlineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self._captcha_image = data["captchaImg"] return self._async_form_auth_captcha(error) + # pylint: disable=broad-exception-raised raise Exception(data) except Exception as err: # pylint: disable=broad-except _LOGGER.error("Error auth user: %s", err) diff --git a/homeassistant/components/twitch/sensor.py b/homeassistant/components/twitch/sensor.py index dcc2dc9bbf6..63746aae46f 100644 --- a/homeassistant/components/twitch/sensor.py +++ b/homeassistant/components/twitch/sensor.py @@ -128,11 +128,13 @@ class TwitchSensor(SensorEntity): elif "status" in subs and subs["status"] == 404: self._attr_extra_state_attributes[ATTR_SUBSCRIPTION] = False elif "error" in subs: - raise Exception( - f"Error response on check_user_subscription: {subs['error']}" + _LOGGER.error( + "Error response on check_user_subscription: %s", subs["error"] ) + return else: - raise Exception("Unknown error response on check_user_subscription") + _LOGGER.error("Unknown error response on check_user_subscription") + return follows = self._client.get_users_follows( from_id=user, to_id=self.unique_id diff --git a/homeassistant/components/xiaomi_miio/light.py b/homeassistant/components/xiaomi_miio/light.py index d691c44a38a..fc38d75d2ca 100644 --- a/homeassistant/components/xiaomi_miio/light.py +++ b/homeassistant/components/xiaomi_miio/light.py @@ -452,9 +452,9 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight): "%s %s%%, %s mireds, %s%% cct" ), brightness, - percent_brightness, + percent_brightness, # pylint: disable=used-before-assignment color_temp, - percent_color_temp, + percent_color_temp, # pylint: disable=used-before-assignment ) result = await self._try_command( @@ -830,8 +830,8 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb): _LOGGER.debug( "Setting brightness and color: %s %s%%, %s", brightness, - percent_brightness, - rgb, + percent_brightness, # pylint: disable=used-before-assignment + rgb, # pylint: disable=used-before-assignment ) result = await self._try_command( @@ -854,7 +854,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb): brightness, percent_brightness, color_temp, - percent_color_temp, + percent_color_temp, # pylint: disable=used-before-assignment ) result = await self._try_command( diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index 552fa29eb86..88f850768ef 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -13,7 +13,7 @@ from collections.abc import Awaitable, Callable import logging import secrets import time -from typing import Any, Optional, cast +from typing import Any, cast from aiohttp import client, web import async_timeout @@ -541,7 +541,7 @@ def _encode_jwt(hass: HomeAssistant, data: dict) -> str: @callback def _decode_jwt(hass: HomeAssistant, encoded: str) -> dict | None: """JWT encode data.""" - secret = cast(Optional[str], hass.data.get(DATA_JWT_SECRET)) + secret: str | None = hass.data.get(DATA_JWT_SECRET) if secret is None: return None diff --git a/pyproject.toml b/pyproject.toml index 371927db4ee..3fe468e9ffc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -161,11 +161,11 @@ good-names = [ # wrong-import-order - isort guards this # consider-using-f-string - str.format sometimes more readable # --- -# Enable once current issues are fixed: -# consider-using-namedtuple-or-dataclass (Pylint CodeStyle extension) -# consider-using-assignment-expr (Pylint CodeStyle extension) +# Pylint CodeStyle plugin +# consider-using-namedtuple-or-dataclass - too opinionated +# consider-using-assignment-expr - decision to use := better left to devs # --- -# Temporary for the Python 3.10 update +# Temporary for the Python 3.10 update, remove with mypy v1.0 # consider-alternative-union-syntax disable = [ "format", @@ -212,9 +212,9 @@ expected-line-ending-format = "LF" [tool.pylint.EXCEPTIONS] overgeneral-exceptions = [ - "BaseException", - "Exception", - "HomeAssistantError", + "builtins.BaseException", + "builtins.Exception", + # "homeassistant.exceptions.HomeAssistantError", # too many issues ] [tool.pylint.TYPING] diff --git a/requirements_test.txt b/requirements_test.txt index 93253105c83..610a6db80f4 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -7,14 +7,14 @@ -c homeassistant/package_constraints.txt -r requirements_test_pre_commit.txt -astroid==2.12.14 +astroid==2.14.1 codecov==2.1.12 coverage==7.0.5 freezegun==1.2.2 mock-open==1.4.0 mypy==0.991 pre-commit==3.0.0 -pylint==2.15.10 +pylint==2.16.0 pylint-per-file-ignores==1.1.0 pipdeptree==2.3.1 pytest-asyncio==0.20.2