1
mirror of https://github.com/home-assistant/core synced 2024-09-21 22:18:00 +02:00

Upgrade pylint (#27279)

* Upgrade pylint to 2.4.2 and astroid to 2.3.1

https://pylint.readthedocs.io/en/latest/whatsnew/2.4.html
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-1
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-2

* unnecessary-comprehension fixes

* invalid-name fixes

* self-assigning-variable fixes

* Re-enable not-an-iterable

* used-before-assignment fix

* invalid-overridden-method fixes

* undefined-variable __class__ workarounds

https://github.com/PyCQA/pylint/issues/3090

* no-member false positive disabling

* Remove some no longer needed disables

* using-constant-test fix

* Disable import-outside-toplevel for now

* Disable some apparent no-value-for-parameter false positives

* invalid-overridden-method false positive disables

https://github.com/PyCQA/pylint/issues/3150

* Fix unintentional Entity.force_update override in AfterShipSensor
This commit is contained in:
Ville Skyttä 2019-10-07 18:17:39 +03:00 committed by Paulus Schoutsen
parent 3adac699c7
commit 761d7f21e9
37 changed files with 67 additions and 44 deletions

View File

@ -146,10 +146,10 @@ class AfterShipSensor(Entity):
async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self.force_update
UPDATE_TOPIC, self._force_update
)
async def force_update(self):
async def _force_update(self):
"""Force update of data."""
await self.async_update(no_throttle=True)
await self.async_update_ha_state()

View File

@ -171,7 +171,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if discovery_info[CONF_HOST].startswith("169.254"):
return self.async_abort(reason="link_local_address")
# pylint: disable=unsupported-assignment-operation
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["macaddress"] = serialnumber
if any(

View File

@ -250,7 +250,7 @@ class BayesianBinarySensor(BinarySensorDevice):
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
ATTR_OBSERVATIONS: [val for val in self.current_obs.values()],
ATTR_OBSERVATIONS: list(self.current_obs.values()),
ATTR_PROBABILITY: round(self.probability, 2),
ATTR_PROBABILITY_THRESHOLD: self._probability_threshold,
}

View File

@ -69,7 +69,7 @@ class BTSmartHubScanner(DeviceScanner):
_LOGGER.warning("Error scanning devices")
return
clients = [client for client in data.values()]
clients = list(data.values())
self.last_results = clients
def get_bt_smarthub_data(self):

View File

@ -11,5 +11,6 @@ def get_cert(host, port):
address = (host, port)
with socket.create_connection(address, timeout=TIMEOUT) as sock:
with ctx.wrap_socket(sock, server_hostname=address[0]) as ssock:
cert = ssock.getpeercert()
# pylint disable: https://github.com/PyCQA/pylint/issues/3166
cert = ssock.getpeercert() # pylint: disable=no-member
return cert

View File

@ -165,4 +165,4 @@ class DdWrtDeviceScanner(DeviceScanner):
def _parse_ddwrt_response(data_str):
"""Parse the DD-WRT data format."""
return {key: val for key, val in _DDWRT_DATA_REGEX.findall(data_str)}
return dict(_DDWRT_DATA_REGEX.findall(data_str))

View File

@ -187,7 +187,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
):
return self.async_abort(reason="already_in_progress")
# pylint: disable=unsupported-assignment-operation
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context[CONF_BRIDGEID] = bridgeid
self.deconz_config = {

View File

@ -126,6 +126,9 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
features |= SUPPORT_PRESET_MODE
return features
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method
@esphome_state_property
def hvac_mode(self) -> Optional[str]:
"""Return current operation ie. heat, cool, idle."""

View File

@ -44,11 +44,12 @@ class EsphomeFlowHandler(config_entries.ConfigFlow):
@property
def _name(self):
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
return self.context.get("name")
@_name.setter
def _name(self, value):
# pylint: disable=unsupported-assignment-operation
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["name"] = value
self.context["title_placeholders"] = {"name": self._name}

View File

@ -70,6 +70,9 @@ class EsphomeCover(EsphomeEntity, CoverDevice):
def _state(self) -> Optional[CoverState]:
return super()._state
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method
@esphome_state_property
def is_closed(self) -> Optional[bool]:
"""Return if the cover is closed or not."""

View File

@ -92,6 +92,9 @@ class EsphomeFan(EsphomeEntity, FanEntity):
key=self._static_info.key, oscillating=oscillating
)
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method
@esphome_state_property
def is_on(self) -> Optional[bool]:
"""Return true if the entity is on."""

View File

@ -61,6 +61,9 @@ class EsphomeLight(EsphomeEntity, Light):
def _state(self) -> Optional[LightState]:
return super()._state
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method
@esphome_state_property
def is_on(self) -> Optional[bool]:
"""Return true if the switch is on."""

View File

@ -37,6 +37,10 @@ async def async_setup_entry(
)
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method
class EsphomeSensor(EsphomeEntity):
"""A sensor implementation for esphome."""

View File

@ -49,6 +49,8 @@ class EsphomeSwitch(EsphomeEntity, SwitchDevice):
"""Return true if we do optimistic updates."""
return self._static_info.assumed_state
# https://github.com/PyCQA/pylint/issues/3150 for @esphome_state_property
# pylint: disable=invalid-overridden-method
@esphome_state_property
def is_on(self) -> Optional[bool]:
"""Return true if the switch is on."""

View File

@ -122,7 +122,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
_LOGGER.debug("Discovered device %s (%s - %s)", name, model, hkid)
# pylint: disable=unsupported-assignment-operation
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["hkid"] = hkid
self.context["title_placeholders"] = {"name": name}

View File

@ -50,6 +50,8 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
def __init__(self):
"""Initialize the Hue flow."""
self.host = None

View File

@ -776,7 +776,9 @@ class MQTT:
self._mqttc.on_message = self._mqtt_on_message
if will_message is not None:
self._mqttc.will_set(*attr.astuple(will_message))
self._mqttc.will_set( # pylint: disable=no-value-for-parameter
*attr.astuple(will_message)
)
async def async_publish(
self, topic: str, payload: PublishPayloadType, qos: int, retain: bool
@ -909,7 +911,11 @@ class MQTT:
self.hass.add_job(self._async_perform_subscription, topic, max_qos)
if self.birth_message:
self.hass.add_job(self.async_publish(*attr.astuple(self.birth_message)))
self.hass.add_job(
self.async_publish( # pylint: disable=no-value-for-parameter
*attr.astuple(self.birth_message)
)
)
def _mqtt_on_message(self, _mqttc, _userdata, msg) -> None:
"""Message received callback."""

View File

@ -264,7 +264,7 @@ class OnkyoDevice(MediaPlayerDevice):
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
self._current_source = "_".join([i for i in current_source_tuples[1]])
self._current_source = "_".join(current_source_tuples[1])
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]
elif ATTR_PRESET in self._attributes:
@ -413,7 +413,7 @@ class OnkyoDeviceZone(OnkyoDevice):
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
self._current_source = "_".join([i for i in current_source_tuples[1]])
self._current_source = "_".join(current_source_tuples[1])
self._muted = bool(mute_raw[1] == "on")
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]

View File

@ -157,7 +157,7 @@ class RMVDepartureSensor(Entity):
"""Return the state attributes."""
try:
return {
"next_departures": [val for val in self.data.departures[1:]],
"next_departures": self.data.departures[1:],
"direction": self.data.departures[0].get("direction"),
"line": self.data.departures[0].get("line"),
"minutes": self.data.departures[0].get("minutes"),

View File

@ -49,6 +49,7 @@ class SabnzbdSensor(Entity):
"""Return the state of the sensor."""
return self._state
@property
def should_poll(self):
"""Don't poll. Will be updated by dispatcher signal."""
return False

View File

@ -105,6 +105,7 @@ class SynologyCamera(Camera):
"""Return true if the device is recording."""
return self._camera.is_recording
@property
def should_poll(self):
"""Update the recording state periodically."""
return True

View File

@ -102,7 +102,7 @@ class TplinkDeviceScanner(DeviceScanner):
self.success_init = self._update_info()
except requests.exceptions.RequestException:
_LOGGER.debug("RequestException in %s", __class__.__name__)
_LOGGER.debug("RequestException in %s", self.__class__.__name__)
def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""
@ -150,7 +150,7 @@ class Tplink1DeviceScanner(DeviceScanner):
try:
self.success_init = self._update_info()
except requests.exceptions.RequestException:
_LOGGER.debug("RequestException in %s", __class__.__name__)
_LOGGER.debug("RequestException in %s", self.__class__.__name__)
def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""

View File

@ -83,7 +83,7 @@ class FlowHandler(config_entries.ConfigFlow):
"""Handle zeroconf discovery."""
host = user_input["host"]
# pylint: disable=unsupported-assignment-operation
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["host"] = host
if any(host == flow["context"]["host"] for flow in self._async_in_progress()):

View File

@ -164,7 +164,6 @@ class PerSecondUPnPIGDSensor(UpnpSensor):
"""Get unit we are measuring in."""
raise NotImplementedError()
@property
def _async_fetch_value(self):
"""Fetch a value from the IGD."""
raise NotImplementedError()

View File

@ -6,7 +6,7 @@ import logging
import voluptuous as vol
from homeassistant.components import group
from homeassistant.const import (
from homeassistant.const import ( # noqa: F401 # STATE_PAUSED/IDLE are API
ATTR_BATTERY_LEVEL,
ATTR_COMMAND,
SERVICE_TOGGLE,
@ -68,8 +68,6 @@ VACUUM_SEND_COMMAND_SERVICE_SCHEMA = ENTITY_SERVICE_SCHEMA.extend(
STATE_CLEANING = "cleaning"
STATE_DOCKED = "docked"
STATE_IDLE = STATE_IDLE
STATE_PAUSED = STATE_PAUSED
STATE_RETURNING = "returning"
STATE_ERROR = "error"

View File

@ -252,7 +252,7 @@ class ValloxServiceHandler:
async def async_handle(self, service):
"""Dispatch a service call."""
method = SERVICE_TO_METHOD.get(service.service)
params = {key: value for key, value in service.data.items()}
params = service.data.copy()
if not hasattr(self, method["method"]):
_LOGGER.error("Service not implemented: %s", method["method"])

View File

@ -283,10 +283,6 @@ class WinkThermostat(WinkDevice, ClimateDevice):
target_temp_high = target_temp
if self.hvac_mode == HVAC_MODE_HEAT:
target_temp_low = target_temp
if target_temp_low is not None:
target_temp_low = target_temp_low
if target_temp_high is not None:
target_temp_high = target_temp_high
self.wink.set_temperature(target_temp_low, target_temp_high)
def set_hvac_mode(self, hvac_mode):

View File

@ -348,7 +348,6 @@ class ZHADevice(LogMixin):
zdo_task = None
for channel in channels:
if channel.name == CHANNEL_ZDO:
# pylint: disable=E1111
if zdo_task is None: # We only want to do this once
zdo_task = self._async_create_task(
semaphore, channel, task_name, *args
@ -373,8 +372,7 @@ class ZHADevice(LogMixin):
@callback
def async_unsub_dispatcher(self):
"""Unsubscribe the dispatcher."""
if self._unsub:
self._unsub()
self._unsub()
@callback
def async_update_last_seen(self, last_seen):

View File

@ -43,7 +43,7 @@ SPEED_LIST = [
SPEED_SMART,
]
VALUE_TO_SPEED = {i: speed for i, speed in enumerate(SPEED_LIST)}
VALUE_TO_SPEED = dict(enumerate(SPEED_LIST))
SPEED_TO_VALUE = {speed: i for i, speed in enumerate(SPEED_LIST)}

View File

@ -27,7 +27,7 @@ _LOGGER = logging.getLogger(__name__)
STATE_LIST = [STATE_UNLOCKED, STATE_LOCKED, STATE_UNLOCKED]
VALUE_TO_STATE = {i: state for i, state in enumerate(STATE_LIST)}
VALUE_TO_STATE = dict(enumerate(STATE_LIST))
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):

View File

@ -186,7 +186,9 @@ class HomeAssistant:
self.data: dict = {}
self.state = CoreState.not_running
self.exit_code = 0
self.config_entries: Optional[ConfigEntries] = None
self.config_entries: Optional[
ConfigEntries # pylint: disable=used-before-assignment
] = None
# If not None, use to signal end-of-loop
self._stopped: Optional[asyncio.Event] = None

View File

@ -38,7 +38,7 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
if user_input is None:
return self.async_show_form(step_id="confirm")
if (
if ( # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context
and self.context.get("source") != config_entries.SOURCE_DISCOVERY
):

View File

@ -167,8 +167,8 @@ COLORS = {
class XYPoint:
"""Represents a CIE 1931 XY coordinate pair."""
x = attr.ib(type=float)
y = attr.ib(type=float)
x = attr.ib(type=float) # pylint: disable=invalid-name
y = attr.ib(type=float) # pylint: disable=invalid-name
@attr.s()

View File

@ -220,7 +220,7 @@ def get_age(date: dt.datetime) -> str:
def parse_time_expression(parameter: Any, min_value: int, max_value: int) -> List[int]:
"""Parse the time expression part and return a list of times to match."""
if parameter is None or parameter == MATCH_ALL:
res = [x for x in range(min_value, max_value + 1)]
res = list(range(min_value, max_value + 1))
elif isinstance(parameter, str) and parameter.startswith("/"):
parameter = int(parameter[1:])
res = [x for x in range(min_value, max_value + 1) if x % parameter == 0]

View File

@ -2,7 +2,7 @@
ignore=tests
[BASIC]
good-names=i,j,k,ex,Run,_,fp
good-names=id,i,j,k,ex,Run,_,fp
[MESSAGES CONTROL]
# Reasons disabled:
@ -18,8 +18,8 @@ good-names=i,j,k,ex,Run,_,fp
# too-few-* - same as too-many-*
# abstract-method - with intro of async there are always methods missing
# inconsistent-return-statements - doesn't handle raise
# not-an-iterable - https://github.com/PyCQA/pylint/issues/2311
# unnecessary-pass - readability for functions which only contain pass
# import-outside-toplevel - TODO
disable=
format,
abstract-class-little-used,
@ -27,9 +27,9 @@ disable=
cyclic-import,
duplicate-code,
global-statement,
import-outside-toplevel,
inconsistent-return-statements,
locally-disabled,
not-an-iterable,
not-context-manager,
redefined-variable-type,
too-few-public-methods,

View File

@ -12,8 +12,8 @@ mock-open==1.3.1
mypy==0.730
pre-commit==1.18.3
pydocstyle==4.0.1
pylint==2.3.1
astroid==2.2.5
pylint==2.4.2
astroid==2.3.1
pytest-aiohttp==0.3.0
pytest-cov==2.7.1
pytest-sugar==0.9.2

View File

@ -13,8 +13,8 @@ mock-open==1.3.1
mypy==0.730
pre-commit==1.18.3
pydocstyle==4.0.1
pylint==2.3.1
astroid==2.2.5
pylint==2.4.2
astroid==2.3.1
pytest-aiohttp==0.3.0
pytest-cov==2.7.1
pytest-sugar==0.9.2