diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 327d5973892f10daf63aa07ff93acb543482a18b..db122e23f13110106cca8fbd21d75f6e5551f13d 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -75,6 +75,8 @@ class AlexaCapability: https://developer.amazon.com/docs/device-apis/message-guide.html """ + # pylint: disable=no-self-use + supported_locales = {"en-US"} def __init__(self, entity: State, instance: str | None = None) -> None: @@ -86,28 +88,23 @@ class AlexaCapability: """Return the Alexa API name of this interface.""" raise NotImplementedError - @staticmethod - def properties_supported() -> list[dict]: + def properties_supported(self) -> list[dict]: """Return what properties this entity supports.""" return [] - @staticmethod - def properties_proactively_reported() -> bool: + def properties_proactively_reported(self) -> bool: """Return True if properties asynchronously reported.""" return False - @staticmethod - def properties_retrievable() -> bool: + def properties_retrievable(self) -> bool: """Return True if properties can be retrieved.""" return False - @staticmethod - def properties_non_controllable() -> bool | None: + def properties_non_controllable(self) -> bool | None: """Return True if non controllable.""" return None - @staticmethod - def get_property(name): + def get_property(self, name): """Read and return a property. Return value should be a dict, or raise UnsupportedProperty. @@ -117,13 +114,11 @@ class AlexaCapability: """ raise UnsupportedProperty(name) - @staticmethod - def supports_deactivation(): + def supports_deactivation(self): """Applicable only to scenes.""" return None - @staticmethod - def capability_proactively_reported(): + def capability_proactively_reported(self): """Return True if the capability is proactively reported. Set properties_proactively_reported() for proactively reported properties. @@ -131,16 +126,14 @@ class AlexaCapability: """ return None - @staticmethod - def capability_resources(): + def capability_resources(self): """Return the capability object. Applicable to ToggleController, RangeController, and ModeController interfaces. """ return [] - @staticmethod - def configuration(): + def configuration(self): """Return the configuration object. Applicable to the ThermostatController, SecurityControlPanel, ModeController, RangeController, @@ -148,8 +141,7 @@ class AlexaCapability: """ return [] - @staticmethod - def configurations(): + def configurations(self): """Return the configurations object. The plural configurations object is different that the singular configuration object. @@ -157,31 +149,29 @@ class AlexaCapability: """ return [] - @staticmethod - def inputs(): + def inputs(self): """Applicable only to media players.""" return [] - @staticmethod - def semantics(): + def semantics(self): """Return the semantics object. Applicable to ToggleController, RangeController, and ModeController interfaces. """ return [] - @staticmethod - def supported_operations(): + def supported_operations(self): """Return the supportedOperations object.""" return [] - @staticmethod - def camera_stream_configurations(): + def camera_stream_configurations(self): """Applicable only to CameraStreamController.""" return None def serialize_discovery(self): """Serialize according to the Discovery API.""" + # pylint: disable=assignment-from-none + # Methods may be overridden and return a value. result = {"type": "AlexaInterface", "interface": self.name(), "version": "3"} if (instance := self.instance) is not None: diff --git a/homeassistant/components/alexa/resources.py b/homeassistant/components/alexa/resources.py index 5c02eca4fb2d281dec100cb53928548910fddeb0..aec43f41f9aa98b5dfbba6d384fc5de02f2a4abf 100644 --- a/homeassistant/components/alexa/resources.py +++ b/homeassistant/components/alexa/resources.py @@ -200,6 +200,8 @@ class AlexaCapabilityResource: https://developer.amazon.com/docs/device-apis/resources-and-assets.html#capability-resources """ + # pylint: disable=no-self-use + def __init__(self, labels): """Initialize an Alexa resource.""" self._resource_labels = [] @@ -210,13 +212,11 @@ class AlexaCapabilityResource: """Return capabilityResources object serialized for an API response.""" return self.serialize_labels(self._resource_labels) - @staticmethod - def serialize_configuration(): + def serialize_configuration(self): """Return ModeResources, PresetResources friendlyNames serialized for an API response.""" return [] - @staticmethod - def serialize_labels(resources): + def serialize_labels(self, resources): """Return resource label objects for friendlyNames serialized for an API response.""" labels = [] for label in resources: diff --git a/homeassistant/components/broadlink/config_flow.py b/homeassistant/components/broadlink/config_flow.py index 8a32ba02ee88ee4a889ffa55b626505b50c11fbd..da8b489a98b6eb1535fe1f5c0d4a1632e8cdd209 100644 --- a/homeassistant/components/broadlink/config_flow.py +++ b/homeassistant/components/broadlink/config_flow.py @@ -188,7 +188,9 @@ class BroadlinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): await self.async_set_unique_id(device.mac.hex()) _LOGGER.error( - "Failed to authenticate to the device at %s: %s", device.host[0], err_msg + "Failed to authenticate to the device at %s: %s", + device.host[0], + err_msg, # pylint: disable=used-before-assignment ) return self.async_show_form(step_id="auth", errors=errors) @@ -251,7 +253,9 @@ class BroadlinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): return await self.async_step_finish() _LOGGER.error( - "Failed to unlock the device at %s: %s", device.host[0], err_msg + "Failed to unlock the device at %s: %s", + device.host[0], + err_msg, # pylint: disable=used-before-assignment ) else: diff --git a/homeassistant/components/color_extractor/__init__.py b/homeassistant/components/color_extractor/__init__.py index cbc5b0c88219ff85374e63afe1d08ff8f4c70430..b0884643be99acaf63fd48adfbf785216a9e4ad6 100644 --- a/homeassistant/components/color_extractor/__init__.py +++ b/homeassistant/components/color_extractor/__init__.py @@ -80,7 +80,7 @@ async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool: except UnidentifiedImageError as ex: _LOGGER.error( "Bad image from %s '%s' provided, are you sure it's an image? %s", - image_type, + image_type, # pylint: disable=used-before-assignment image_reference, ex, ) diff --git a/homeassistant/components/harmony/subscriber.py b/homeassistant/components/harmony/subscriber.py index f71b486fd1687af447da51c84625b2c67f3d5401..2731d8555f0ab834d8f310090ec2146c1f9603a1 100644 --- a/homeassistant/components/harmony/subscriber.py +++ b/homeassistant/components/harmony/subscriber.py @@ -3,7 +3,6 @@ import asyncio import logging -# pylint: disable-next=deprecated-typing-alias # Issue with Python 3.9.0 and 3.9.1 with collections.abc.Callable # https://bugs.python.org/issue42965 from typing import Any, Callable, NamedTuple, Optional diff --git a/homeassistant/components/horizon/media_player.py b/homeassistant/components/horizon/media_player.py index 31e905b7864859ea94b6d509f964407906aa193a..fd6b7b3d3cc02a4b8a7b8fb81251dbba62f07dca 100644 --- a/homeassistant/components/horizon/media_player.py +++ b/homeassistant/components/horizon/media_player.py @@ -202,12 +202,12 @@ class HorizonDevice(MediaPlayerEntity): try: self._client.connect() self._client.authorize() - except AuthenticationError as msg: - _LOGGER.error("Authentication to %s failed: %s", self._name, msg) + except AuthenticationError as msg2: + _LOGGER.error("Authentication to %s failed: %s", self._name, msg2) return - except OSError as msg: + except OSError as msg2: # occurs if horizon box is offline - _LOGGER.error("Reconnect to %s failed: %s", self._name, msg) + _LOGGER.error("Reconnect to %s failed: %s", self._name, msg2) return self._send(key=key, channel=channel) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index a41329a1548917d43169ab91e5d1694d2ca31121..374e69975cee07b419ed99bf6ba264b51bea548e 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -365,10 +365,10 @@ class HomeAssistantHTTP: ) try: context = self._create_emergency_ssl_context() - except OSError as error: + except OSError as error2: _LOGGER.error( "Could not create an emergency self signed ssl certificate: %s", - error, + error2, ) context = None else: diff --git a/homeassistant/components/icloud/config_flow.py b/homeassistant/components/icloud/config_flow.py index 9bfa12a76a22d6b1b20c58518a8e2d1333f53d84..3eb6ced782cedf0e105d2f1a040af1ab75aa0906 100644 --- a/homeassistant/components/icloud/config_flow.py +++ b/homeassistant/components/icloud/config_flow.py @@ -288,8 +288,8 @@ class IcloudFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self._with_family, ) return await self.async_step_verification_code(None, errors) - except PyiCloudFailedLoginException as error: - _LOGGER.error("Error logging into iCloud service: %s", error) + except PyiCloudFailedLoginException as error_login: + _LOGGER.error("Error logging into iCloud service: %s", error_login) self.api = None errors = {CONF_PASSWORD: "invalid_auth"} return self._show_setup_form(user_input, errors, "user") diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 660b6355911992d267450e074a65fef49d5ef988..71ac332d34e8cb3202fecbc3bd46f7d3f824c9f0 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -528,8 +528,6 @@ class LazyState(State): __slots__ = [ "_row", - "entity_id", - "state", "_attributes", "_last_changed", "_last_updated", diff --git a/homeassistant/components/solaredge_local/sensor.py b/homeassistant/components/solaredge_local/sensor.py index 368121e79e9ab7b30013d155a842cb37020688c3..d07a95683eb5365ba01ccc9884489456e2c36fa1 100644 --- a/homeassistant/components/solaredge_local/sensor.py +++ b/homeassistant/components/solaredge_local/sensor.py @@ -209,7 +209,6 @@ def setup_platform( _LOGGER.debug("Credentials correct and site is active") except AttributeError: _LOGGER.error("Missing details data in solaredge status") - _LOGGER.debug("Status is: %s", status) return except (ConnectTimeout, HTTPError): _LOGGER.error("Could not retrieve details from SolarEdge API") diff --git a/homeassistant/components/sonos/__init__.py b/homeassistant/components/sonos/__init__.py index 27d51d8f3e63a222e7ec6ba3cb1b9d11e41f9992..bb4c61fdadf951558328e1f17d955383874cc418 100644 --- a/homeassistant/components/sonos/__init__.py +++ b/homeassistant/components/sonos/__init__.py @@ -188,6 +188,7 @@ class SonosDiscoveryManager: _ = soco.volume return soco except NotSupportedException as exc: + # pylint: disable-next=used-before-assignment _LOGGER.debug("Device %s is not supported, ignoring: %s", uid, exc) self.data.discovery_ignored.add(ip_address) except (OSError, SoCoException) as ex: diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index ad6c8142828743976b635a63d4fcebf438fdef90..97422179960aa8bebcb516ae7aaf52f231af51e9 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -234,6 +234,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: class DeviceListener(TuyaDeviceListener): """Device Update Listener.""" + # pylint: disable=arguments-differ + # Library incorrectly defines methods as 'classmethod' + # https://github.com/tuya/tuya-iot-python-sdk/pull/48 + def __init__( self, hass: HomeAssistant, diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 6c600bf93d6d28889c67923143354dc2bf66a338..18213c396ccee9ff15ff683dec8f196e1b210b39 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -98,6 +98,8 @@ if TYPE_CHECKING: from ..entity import ZhaEntity from .store import ZhaStorage + # pylint: disable-next=broken-collections-callable + # Safe inside TYPE_CHECKING block _LogFilterType = Union[Filter, Callable[[LogRecord], int]] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 1e7d4f28a38c6631caa0d33eb5a8f4dbd1bf9211..302bbc2a054afea0e0c2be44949cb3a7d08003d4 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -231,7 +231,7 @@ class Battery(Sensor): return cls(unique_id, zha_device, channels, **kwargs) @staticmethod - def formatter(value: int) -> int: + def formatter(value: int) -> int: # pylint: disable=arguments-differ """Return the state of the entity.""" # per zcl specs battery percent is reported at 200% ¯\_(ツ)_/¯ if not isinstance(value, numbers.Number) or value == -1: @@ -391,8 +391,7 @@ class Illuminance(Sensor): _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT _unit = LIGHT_LUX - @staticmethod - def formatter(value: int) -> float: + def formatter(self, value: int) -> float: """Convert illumination data.""" return round(pow(10, ((value - 1) / 10000)), 1) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 7bc37bcd3057aff854b06f0446a5d3a8a871352b..0e94aa458a30fcd8bc0ea1c2084f5979e56fcf5c 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1187,7 +1187,7 @@ async def _old_conf_migrator(old_config: dict[str, Any]) -> dict[str, Any]: class ConfigFlow(data_entry_flow.FlowHandler): """Base class for config flows with some helpers.""" - def __init_subclass__(cls, domain: str | None = None, **kwargs: Any) -> None: + def __init_subclass__(cls, *, domain: str | None = None, **kwargs: Any) -> None: """Initialize a subclass, register if possible.""" super().__init_subclass__(**kwargs) if domain is not None: diff --git a/homeassistant/core.py b/homeassistant/core.py index 11d90d6d05b3b0785b49e0e349dbef694cf35fa2..733281aa5e68e18f1451be06086c2746bb0bb891 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -101,7 +101,7 @@ block_async_io.enable() _T = TypeVar("_T") _R = TypeVar("_R") -_R_co = TypeVar("_R_co", covariant=True) # pylint: disable=invalid-name +_R_co = TypeVar("_R_co", covariant=True) # Internal; not helpers.typing.UNDEFINED due to circular dependency _UNDEF: dict[Any, Any] = {} _CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) diff --git a/homeassistant/helpers/helper_config_entry_flow.py b/homeassistant/helpers/helper_config_entry_flow.py index ba62d5d59e5d4c6a996be893bb806ca0c87ef177..16471c13e418e8f71b0379f255dabef9231805e2 100644 --- a/homeassistant/helpers/helper_config_entry_flow.py +++ b/homeassistant/helpers/helper_config_entry_flow.py @@ -181,7 +181,6 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow): VERSION = 1 - # pylint: disable-next=arguments-differ def __init_subclass__(cls, **kwargs: Any) -> None: """Initialize a subclass.""" super().__init_subclass__(**kwargs) diff --git a/pyproject.toml b/pyproject.toml index c1a08a3f0c3c4d063333e3e5e46d2d3cb468c88d..fbe9fa4b6e84dddb2234827838a8c71031f5cd65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,6 @@ good-names = [ "j", "k", "Run", - "T", "ip", ] diff --git a/requirements_test.txt b/requirements_test.txt index a78f7d57a7b1063c44a16e689928f41e252bdf4d..34a4936b3d845e03a3947b9924fc9e1e67ad8882 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -13,7 +13,7 @@ freezegun==1.2.1 mock-open==1.4.0 mypy==0.942 pre-commit==2.17.0 -pylint==2.12.2 +pylint==2.13.0 pipdeptree==2.2.1 pylint-strict-informational==0.1 pytest-aiohttp==0.3.0 diff --git a/tests/pylint/test_enforce_type_hints.py b/tests/pylint/test_enforce_type_hints.py index 81fdd2fa916bb54e95ede12521a7d5f8ddb0f5b9..64be85c9a44e523da79575f167a3899c1e6903d2 100644 --- a/tests/pylint/test_enforce_type_hints.py +++ b/tests/pylint/test_enforce_type_hints.py @@ -137,6 +137,10 @@ def test_invalid_discovery_info( msg_id="hass-argument-type", node=discovery_info_node, args=(4, "DiscoveryInfoType | None"), + line=6, + col_offset=4, + end_line=6, + end_col_offset=41, ), ): type_hint_checker.visit_asyncfunctiondef(func_node)