From 1be440a72b79c96d633ed796b16f802e6aa0a1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 6 Dec 2018 12:54:44 +0200 Subject: [PATCH] Upgrade pylint to 2.2.2 (#18750) * Upgrade to 2.2.0 * simplifiable-if-expression fixes * duplicate-string-formatting-argument fixes * unused-import fixes * Upgrade to 2.2.1 * Remove no longer needed disable * Upgrade to 2.2.2 --- .../components/binary_sensor/alarmdecoder.py | 16 ++++++++-------- .../components/binary_sensor/mystrom.py | 3 +-- homeassistant/components/frontend/__init__.py | 4 ++-- homeassistant/components/homekit/__init__.py | 2 +- homeassistant/components/homekit/type_fans.py | 2 +- .../components/media_player/bluesound.py | 2 +- .../components/media_player/ue_smart_radio.py | 2 +- .../components/owntracks/config_flow.py | 3 +-- homeassistant/components/sensor/bme680.py | 6 ++---- homeassistant/components/sensor/miflora.py | 2 +- homeassistant/components/sensor/mitemp_bt.py | 2 +- homeassistant/components/sensor/mvglive.py | 8 ++++---- homeassistant/components/sensor/statistics.py | 3 +-- homeassistant/components/spaceapi.py | 2 +- homeassistant/components/switch/raspihats.py | 4 ++-- homeassistant/config.py | 7 ++++--- homeassistant/helpers/intent.py | 3 +-- requirements_test.txt | 2 +- requirements_test_all.txt | 2 +- 19 files changed, 35 insertions(+), 40 deletions(-) diff --git a/homeassistant/components/binary_sensor/alarmdecoder.py b/homeassistant/components/binary_sensor/alarmdecoder.py index 1b50d6c6c72..f7a42e9b831 100644 --- a/homeassistant/components/binary_sensor/alarmdecoder.py +++ b/homeassistant/components/binary_sensor/alarmdecoder.py @@ -92,14 +92,14 @@ class AlarmDecoderBinarySensor(BinarySensorDevice): """Return the state attributes.""" attr = {} if self._rfid and self._rfstate is not None: - attr[ATTR_RF_BIT0] = True if self._rfstate & 0x01 else False - attr[ATTR_RF_LOW_BAT] = True if self._rfstate & 0x02 else False - attr[ATTR_RF_SUPERVISED] = True if self._rfstate & 0x04 else False - attr[ATTR_RF_BIT3] = True if self._rfstate & 0x08 else False - attr[ATTR_RF_LOOP3] = True if self._rfstate & 0x10 else False - attr[ATTR_RF_LOOP2] = True if self._rfstate & 0x20 else False - attr[ATTR_RF_LOOP4] = True if self._rfstate & 0x40 else False - attr[ATTR_RF_LOOP1] = True if self._rfstate & 0x80 else False + attr[ATTR_RF_BIT0] = bool(self._rfstate & 0x01) + attr[ATTR_RF_LOW_BAT] = bool(self._rfstate & 0x02) + attr[ATTR_RF_SUPERVISED] = bool(self._rfstate & 0x04) + attr[ATTR_RF_BIT3] = bool(self._rfstate & 0x08) + attr[ATTR_RF_LOOP3] = bool(self._rfstate & 0x10) + attr[ATTR_RF_LOOP2] = bool(self._rfstate & 0x20) + attr[ATTR_RF_LOOP4] = bool(self._rfstate & 0x40) + attr[ATTR_RF_LOOP1] = bool(self._rfstate & 0x80) return attr @property diff --git a/homeassistant/components/binary_sensor/mystrom.py b/homeassistant/components/binary_sensor/mystrom.py index 5785ed464fd..4927be27eb3 100644 --- a/homeassistant/components/binary_sensor/mystrom.py +++ b/homeassistant/components/binary_sensor/mystrom.py @@ -61,8 +61,7 @@ class MyStromView(HomeAssistantView): '{}_{}'.format(button_id, button_action)) self.add_entities([self.buttons[entity_id]]) else: - new_state = True if self.buttons[entity_id].state == 'off' \ - else False + new_state = self.buttons[entity_id].state == 'off' self.buttons[entity_id].async_on_update(new_state) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 43a4839bf43..77c98ab6aa2 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -55,8 +55,8 @@ MANIFEST_JSON = { for size in (192, 384, 512, 1024): MANIFEST_JSON['icons'].append({ - 'src': '/static/icons/favicon-{}x{}.png'.format(size, size), - 'sizes': '{}x{}'.format(size, size), + 'src': '/static/icons/favicon-{size}x{size}.png'.format(size=size), + 'sizes': '{size}x{size}'.format(size=size), 'type': 'image/png' }) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index da8daf50f2a..c8aea5f8fb3 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -245,7 +245,7 @@ class HomeKit(): return self.status = STATUS_WAIT - # pylint: disable=unused-variable + # pylint: disable=unused-import from . import ( # noqa F401 type_covers, type_fans, type_lights, type_locks, type_media_players, type_security_systems, type_sensors, diff --git a/homeassistant/components/homekit/type_fans.py b/homeassistant/components/homekit/type_fans.py index 5a860ed21c8..2b4e55c4c8d 100644 --- a/homeassistant/components/homekit/type_fans.py +++ b/homeassistant/components/homekit/type_fans.py @@ -78,7 +78,7 @@ class Fan(HomeAccessory): """Set state if call came from HomeKit.""" _LOGGER.debug('%s: Set oscillating to %d', self.entity_id, value) self._flag[CHAR_SWING_MODE] = True - oscillating = True if value == 1 else False + oscillating = value == 1 params = {ATTR_ENTITY_ID: self.entity_id, ATTR_OSCILLATING: oscillating} self.call_service(DOMAIN, SERVICE_OSCILLATE, params, oscillating) diff --git a/homeassistant/components/media_player/bluesound.py b/homeassistant/components/media_player/bluesound.py index f4ed62b15cd..998f559bc8a 100644 --- a/homeassistant/components/media_player/bluesound.py +++ b/homeassistant/components/media_player/bluesound.py @@ -779,7 +779,7 @@ class BluesoundPlayer(MediaPlayerDevice): @property def shuffle(self): """Return true if shuffle is active.""" - return True if self._status.get('shuffle', '0') == '1' else False + return self._status.get('shuffle', '0') == '1' async def async_join(self, master): """Join the player to a group.""" diff --git a/homeassistant/components/media_player/ue_smart_radio.py b/homeassistant/components/media_player/ue_smart_radio.py index 066972aaa25..75f6d92a98c 100644 --- a/homeassistant/components/media_player/ue_smart_radio.py +++ b/homeassistant/components/media_player/ue_smart_radio.py @@ -136,7 +136,7 @@ class UERadioDevice(MediaPlayerDevice): @property def is_volume_muted(self): """Boolean if volume is currently muted.""" - return True if self._volume <= 0 else False + return self._volume <= 0 @property def volume_level(self): diff --git a/homeassistant/components/owntracks/config_flow.py b/homeassistant/components/owntracks/config_flow.py index 8cf19e84bcd..6818efbbf75 100644 --- a/homeassistant/components/owntracks/config_flow.py +++ b/homeassistant/components/owntracks/config_flow.py @@ -9,8 +9,7 @@ CONF_SECRET = 'secret' def supports_encryption(): """Test if we support encryption.""" try: - # pylint: disable=unused-variable - import libnacl # noqa + import libnacl # noqa pylint: disable=unused-import return True except OSError: return False diff --git a/homeassistant/components/sensor/bme680.py b/homeassistant/components/sensor/bme680.py index cbcb7f1080e..64d28c25bf0 100644 --- a/homeassistant/components/sensor/bme680.py +++ b/homeassistant/components/sensor/bme680.py @@ -179,10 +179,8 @@ def _setup_bme680(config): sensor_handler = BME680Handler( sensor, - True if ( - SENSOR_GAS in config[CONF_MONITORED_CONDITIONS] or - SENSOR_AQ in config[CONF_MONITORED_CONDITIONS] - ) else False, + (SENSOR_GAS in config[CONF_MONITORED_CONDITIONS] or + SENSOR_AQ in config[CONF_MONITORED_CONDITIONS]), config[CONF_AQ_BURN_IN_TIME], config[CONF_AQ_HUM_BASELINE], config[CONF_AQ_HUM_WEIGHTING] diff --git a/homeassistant/components/sensor/miflora.py b/homeassistant/components/sensor/miflora.py index 74bb8261609..412b339caf3 100644 --- a/homeassistant/components/sensor/miflora.py +++ b/homeassistant/components/sensor/miflora.py @@ -55,7 +55,7 @@ async def async_setup_platform(hass, config, async_add_entities, """Set up the MiFlora sensor.""" from miflora import miflora_poller try: - import bluepy.btle # noqa: F401 pylint: disable=unused-variable + import bluepy.btle # noqa: F401 pylint: disable=unused-import from btlewrap import BluepyBackend backend = BluepyBackend except ImportError: diff --git a/homeassistant/components/sensor/mitemp_bt.py b/homeassistant/components/sensor/mitemp_bt.py index 2ae5c29b043..15e225fd2c0 100644 --- a/homeassistant/components/sensor/mitemp_bt.py +++ b/homeassistant/components/sensor/mitemp_bt.py @@ -60,7 +60,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the MiTempBt sensor.""" from mitemp_bt import mitemp_bt_poller try: - import bluepy.btle # noqa: F401 pylint: disable=unused-variable + import bluepy.btle # noqa: F401 pylint: disable=unused-import from btlewrap import BluepyBackend backend = BluepyBackend except ImportError: diff --git a/homeassistant/components/sensor/mvglive.py b/homeassistant/components/sensor/mvglive.py index 8634e4f4570..5ec66aafe2f 100644 --- a/homeassistant/components/sensor/mvglive.py +++ b/homeassistant/components/sensor/mvglive.py @@ -147,10 +147,10 @@ class MVGLiveData: self._products = products self._timeoffset = timeoffset self._number = number - self._include_ubahn = True if 'U-Bahn' in self._products else False - self._include_tram = True if 'Tram' in self._products else False - self._include_bus = True if 'Bus' in self._products else False - self._include_sbahn = True if 'S-Bahn' in self._products else False + self._include_ubahn = 'U-Bahn' in self._products + self._include_tram = 'Tram' in self._products + self._include_bus = 'Bus' in self._products + self._include_sbahn = 'S-Bahn' in self._products self.mvg = MVGLive.MVGLive() self.departures = [] diff --git a/homeassistant/components/sensor/statistics.py b/homeassistant/components/sensor/statistics.py index e011121f4a2..01c783dc1db 100644 --- a/homeassistant/components/sensor/statistics.py +++ b/homeassistant/components/sensor/statistics.py @@ -80,8 +80,7 @@ class StatisticsSensor(Entity): precision): """Initialize the Statistics sensor.""" self._entity_id = entity_id - self.is_binary = True if self._entity_id.split('.')[0] == \ - 'binary_sensor' else False + self.is_binary = self._entity_id.split('.')[0] == 'binary_sensor' if not self.is_binary: self._name = '{} {}'.format(name, ATTR_MEAN) else: diff --git a/homeassistant/components/spaceapi.py b/homeassistant/components/spaceapi.py index eaf1508071a..fa2e5e8e1ea 100644 --- a/homeassistant/components/spaceapi.py +++ b/homeassistant/components/spaceapi.py @@ -129,7 +129,7 @@ class APISpaceApiView(HomeAssistantView): if space_state is not None: state = { - ATTR_OPEN: False if space_state.state == 'off' else True, + ATTR_OPEN: space_state.state != 'off', ATTR_LASTCHANGE: dt_util.as_timestamp(space_state.last_updated), } diff --git a/homeassistant/components/switch/raspihats.py b/homeassistant/components/switch/raspihats.py index c697d7042a6..b422efea2ff 100644 --- a/homeassistant/components/switch/raspihats.py +++ b/homeassistant/components/switch/raspihats.py @@ -123,7 +123,7 @@ class I2CHatSwitch(ToggleEntity): def turn_on(self, **kwargs): """Turn the device on.""" try: - state = True if self._invert_logic is False else False + state = self._invert_logic is False self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state) self.schedule_update_ha_state() except I2CHatsException as ex: @@ -132,7 +132,7 @@ class I2CHatSwitch(ToggleEntity): def turn_off(self, **kwargs): """Turn the device off.""" try: - state = False if self._invert_logic is False else True + state = self._invert_logic is not False self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state) self.schedule_update_ha_state() except I2CHatsException as ex: diff --git a/homeassistant/config.py b/homeassistant/config.py index 4fc77bd81cd..10d3ce21a00 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -437,9 +437,10 @@ def _format_config_error(ex: vol.Invalid, domain: str, config: Dict) -> str: """ message = "Invalid config for [{}]: ".format(domain) if 'extra keys not allowed' in ex.error_message: - message += '[{}] is an invalid option for [{}]. Check: {}->{}.'\ - .format(ex.path[-1], domain, domain, - '->'.join(str(m) for m in ex.path)) + message += '[{option}] is an invalid option for [{domain}]. ' \ + 'Check: {domain}->{path}.'.format( + option=ex.path[-1], domain=domain, + path='->'.join(str(m) for m in ex.path)) else: message += '{}.'.format(humanize_error(config, ex)) diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index d942aabccce..f4d57ce86cd 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -68,8 +68,7 @@ async def async_handle(hass: HomeAssistantType, platform: str, intent_type, err) raise InvalidSlotInfo( 'Received invalid slot info for {}'.format(intent_type)) from err - # https://github.com/PyCQA/pylint/issues/2284 - except IntentHandleError: # pylint: disable=try-except-raise + except IntentHandleError: raise except Exception as err: raise IntentUnexpectedError( diff --git a/requirements_test.txt b/requirements_test.txt index 8d761c1e614..d9c52bbd053 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -8,7 +8,7 @@ flake8==3.6.0 mock-open==1.3.1 mypy==0.641 pydocstyle==2.1.1 -pylint==2.1.1 +pylint==2.2.2 pytest-aiohttp==0.3.0 pytest-cov==2.6.0 pytest-sugar==0.9.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c63fb9a1200..5105350739a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -9,7 +9,7 @@ flake8==3.6.0 mock-open==1.3.1 mypy==0.641 pydocstyle==2.1.1 -pylint==2.1.1 +pylint==2.2.2 pytest-aiohttp==0.3.0 pytest-cov==2.6.0 pytest-sugar==0.9.2