Skip to content

Commit

Permalink
Update pylint to 2.13.0 (home-assistant#68656)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Mar 25, 2022
1 parent 225f7a9 commit 53245c6
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 55 deletions.
46 changes: 18 additions & 28 deletions homeassistant/components/alexa/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -86,28 +88,23 @@ def name(self) -> str:
"""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.
Expand All @@ -117,71 +114,64 @@ def get_property(name):
"""
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.
Applicable to DoorbellEventSource.
"""
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,
and EventDetectionSensor.
"""
return []

@staticmethod
def configurations():
def configurations(self):
"""Return the configurations object.
The plural configurations object is different that the singular configuration object.
Applicable to EqualizerController interface.
"""
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:
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/alexa/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -210,13 +212,11 @@ def serialize_capability_resources(self):
"""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:
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/broadlink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ async def async_step_auth(self):

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)

Expand Down Expand Up @@ -251,7 +253,9 @@ async def async_step_unlock(self, user_input=None):
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/color_extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def async_handle_service(service_call: ServiceCall) -> None:
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,
)
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/harmony/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/horizon/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ def _send(self, key=None, channel=None):
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)
4 changes: 2 additions & 2 deletions homeassistant/components/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ def _create_ssl_context(self) -> ssl.SSLContext | None:
)
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:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/icloud/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ async def async_step_verification_code(self, user_input=None, errors=None):
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")
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/recorder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,6 @@ class LazyState(State):

__slots__ = [
"_row",
"entity_id",
"state",
"_attributes",
"_last_changed",
"_last_updated",
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/solaredge_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/sonos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _create_soco(self, ip_address: str, source: SoCoCreationSource) -> SoCo | No
_ = 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:
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/zha/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
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__)
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/zha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def create_entity(
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:
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

_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])
Expand Down
1 change: 0 additions & 1 deletion homeassistant/helpers/helper_config_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ good-names = [
"j",
"k",
"Run",
"T",
"ip",
]

Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/pylint/test_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ async def async_setup_scanner( #@
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)
Expand Down

0 comments on commit 53245c6

Please sign in to comment.