From f73fd7300d01c5274ff4ed16682e2bfd9f74d5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 27 Jan 2018 22:13:46 +0200 Subject: [PATCH 1/3] Upgrade flake8 to 3.5 --- requirements_test.txt | 2 +- requirements_test_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_test.txt b/requirements_test.txt index 22bb6623e164..5ba27b4b2903 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,7 +1,7 @@ # linters such as flake8 and pylint should be pinned, as new releases # make new things fail. Manually update these pins when pulling in a # new version -flake8==3.3 +flake8==3.5 pylint==1.6.5 mypy==0.560 pydocstyle==1.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 9bb41e09c24a..8d3e823a989b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2,7 +2,7 @@ # linters such as flake8 and pylint should be pinned, as new releases # make new things fail. Manually update these pins when pulling in a # new version -flake8==3.3 +flake8==3.5 pylint==1.6.5 mypy==0.560 pydocstyle==1.1.1 From e6764a568b4c9d4348a739bf205f72e2422f154a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 27 Jan 2018 22:14:18 +0200 Subject: [PATCH 2/3] Fix flake8 bare except errors --- homeassistant/components/feedreader.py | 6 ++---- homeassistant/components/media_player/bluesound.py | 6 +++--- homeassistant/components/media_player/clementine.py | 2 +- homeassistant/components/sensor/fritzbox_callmonitor.py | 3 +-- homeassistant/components/sensor/qnap.py | 3 +-- homeassistant/components/sensor/synologydsm.py | 3 +-- homeassistant/components/spc.py | 2 +- homeassistant/monkey_patch.py | 2 +- tests/components/emulated_hue/test_upnp.py | 3 +-- tests/components/test_system_log.py | 2 +- 10 files changed, 13 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/feedreader.py b/homeassistant/components/feedreader.py index 3d73901b4d8a..5b9dd076c7fc 100644 --- a/homeassistant/components/feedreader.py +++ b/homeassistant/components/feedreader.py @@ -153,8 +153,7 @@ def _fetch_data(self): with self._lock, open(self._data_file, 'rb') as myfile: self._data = pickle.load(myfile) or {} self._cache_outdated = False - # pylint: disable=bare-except - except: + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.error("Error loading data from pickled file %s", self._data_file) @@ -172,8 +171,7 @@ def put_timestamp(self, url, timestamp): url, self._data_file) try: pickle.dump(self._data, myfile) - # pylint: disable=bare-except - except: + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.error( "Error saving pickled data to %s", self._data_file) self._cache_outdated = True diff --git a/homeassistant/components/media_player/bluesound.py b/homeassistant/components/media_player/bluesound.py index 96323579822f..d8a0cd7ebf9f 100644 --- a/homeassistant/components/media_player/bluesound.py +++ b/homeassistant/components/media_player/bluesound.py @@ -165,7 +165,7 @@ def _internal_update_sync_status( try: resp = yield from self.send_bluesound_command( 'SyncStatus', raise_timeout, raise_timeout) - except: + except Exception: raise if not resp: @@ -202,7 +202,7 @@ def _start_poll_command(self): except CancelledError: _LOGGER.debug("Stopping the polling of node %s", self._name) - except: + except Exception: _LOGGER.exception("Unexpected error in %s", self._name) raise @@ -229,7 +229,7 @@ def async_init(self): _LOGGER.info("Node %s is offline, retrying later", self.host) self._retry_remove = async_track_time_interval( self._hass, self.async_init, NODE_RETRY_INITIATION) - except: + except Exception: _LOGGER.exception("Unexpected when initiating error in %s", self.host) raise diff --git a/homeassistant/components/media_player/clementine.py b/homeassistant/components/media_player/clementine.py index d9688badcd19..057a23579ca2 100644 --- a/homeassistant/components/media_player/clementine.py +++ b/homeassistant/components/media_player/clementine.py @@ -97,7 +97,7 @@ def update(self): self._track_artist = client.current_track['track_artist'] self._track_album_name = client.current_track['track_album'] - except: + except Exception: self._state = STATE_OFF raise diff --git a/homeassistant/components/sensor/fritzbox_callmonitor.py b/homeassistant/components/sensor/fritzbox_callmonitor.py index ea6382ce7958..0903d34374d7 100644 --- a/homeassistant/components/sensor/fritzbox_callmonitor.py +++ b/homeassistant/components/sensor/fritzbox_callmonitor.py @@ -70,8 +70,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): phonebook = FritzBoxPhonebook( host=host, port=port, username=username, password=password, phonebook_id=phonebook_id, prefixes=prefixes) - # pylint: disable=bare-except - except: + except: # pylint: disable=bare-except # noqa: E722 phonebook = None _LOGGER.warning("Phonebook with ID %s not found on Fritz!Box", phonebook_id) diff --git a/homeassistant/components/sensor/qnap.py b/homeassistant/components/sensor/qnap.py index 20460f9063c0..74fc78a4a211 100644 --- a/homeassistant/components/sensor/qnap.py +++ b/homeassistant/components/sensor/qnap.py @@ -197,7 +197,6 @@ def __init__(self, config): self.data = {} - # pylint: disable=bare-except @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update API information and store locally.""" @@ -207,7 +206,7 @@ def update(self): self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() - except: + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.exception("Failed to fetch QNAP stats from the NAS") diff --git a/homeassistant/components/sensor/synologydsm.py b/homeassistant/components/sensor/synologydsm.py index cfc868de6645..bfd1b17db084 100644 --- a/homeassistant/components/sensor/synologydsm.py +++ b/homeassistant/components/sensor/synologydsm.py @@ -136,7 +136,6 @@ def run_setup(event): class SynoApi(object): """Class to interface with Synology DSM API.""" - # pylint: disable=bare-except def __init__(self, host, port, username, password, temp_unit): """Initialize the API wrapper class.""" from SynologyDSM import SynologyDSM @@ -144,7 +143,7 @@ def __init__(self, host, port, username, password, temp_unit): try: self._api = SynologyDSM(host, port, username, password) - except: + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.error("Error setting up Synology DSM") # Will be updated when update() gets called. diff --git a/homeassistant/components/spc.py b/homeassistant/components/spc.py index 141d06768e30..60d191184e17 100644 --- a/homeassistant/components/spc.py +++ b/homeassistant/components/spc.py @@ -151,7 +151,7 @@ def _ws_process_message(message, async_callback, *args): "Unsuccessful websocket message delivered, ignoring: %s", message) try: yield from async_callback(message['data']['sia'], *args) - except: # pylint: disable=bare-except + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.exception("Exception in callback, ignoring") diff --git a/homeassistant/monkey_patch.py b/homeassistant/monkey_patch.py index 819d8de48e02..940131d01f83 100644 --- a/homeassistant/monkey_patch.py +++ b/homeassistant/monkey_patch.py @@ -37,7 +37,7 @@ def add(self, other): asyncio.tasks.Task._all_tasks = IgnoreCalls() try: del asyncio.tasks.Task.__del__ - except: + except Exception: pass diff --git a/tests/components/emulated_hue/test_upnp.py b/tests/components/emulated_hue/test_upnp.py index 1cd895954dea..da40bf37cce9 100644 --- a/tests/components/emulated_hue/test_upnp.py +++ b/tests/components/emulated_hue/test_upnp.py @@ -87,10 +87,9 @@ def test_description_xml(self): self.assertTrue('text/xml' in result.headers['content-type']) # Make sure the XML is parsable - # pylint: disable=bare-except try: ET.fromstring(result.text) - except: + except: # pylint: disable=bare-except # noqa: E722 self.fail('description.xml is not valid XML!') def test_create_username(self): diff --git a/tests/components/test_system_log.py b/tests/components/test_system_log.py index a3e7d662483c..85b763c0fbde 100644 --- a/tests/components/test_system_log.py +++ b/tests/components/test_system_log.py @@ -34,7 +34,7 @@ def get_error_log(hass, test_client, expected_count): def _generate_and_log_exception(exception, log): try: raise Exception(exception) - except: # pylint: disable=bare-except + except: # pylint: disable=bare-except # noqa: E722 _LOGGER.exception(log) From 44a822fe93392a5ed37f680c9450789034c6276a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 29 Jan 2018 06:57:06 +0200 Subject: [PATCH 3/3] Make flake8 and pylint cooperate --- homeassistant/components/feedreader.py | 4 ++-- homeassistant/components/sensor/fritzbox_callmonitor.py | 2 +- homeassistant/components/sensor/qnap.py | 2 +- homeassistant/components/sensor/synologydsm.py | 2 +- homeassistant/components/spc.py | 2 +- homeassistant/monkey_patch.py | 2 +- tests/components/emulated_hue/test_upnp.py | 2 +- tests/components/test_system_log.py | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/feedreader.py b/homeassistant/components/feedreader.py index 5b9dd076c7fc..2c0e146491a6 100644 --- a/homeassistant/components/feedreader.py +++ b/homeassistant/components/feedreader.py @@ -153,7 +153,7 @@ def _fetch_data(self): with self._lock, open(self._data_file, 'rb') as myfile: self._data = pickle.load(myfile) or {} self._cache_outdated = False - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.error("Error loading data from pickled file %s", self._data_file) @@ -171,7 +171,7 @@ def put_timestamp(self, url, timestamp): url, self._data_file) try: pickle.dump(self._data, myfile) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.error( "Error saving pickled data to %s", self._data_file) self._cache_outdated = True diff --git a/homeassistant/components/sensor/fritzbox_callmonitor.py b/homeassistant/components/sensor/fritzbox_callmonitor.py index 0903d34374d7..b443bd56f03d 100644 --- a/homeassistant/components/sensor/fritzbox_callmonitor.py +++ b/homeassistant/components/sensor/fritzbox_callmonitor.py @@ -70,7 +70,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): phonebook = FritzBoxPhonebook( host=host, port=port, username=username, password=password, phonebook_id=phonebook_id, prefixes=prefixes) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except phonebook = None _LOGGER.warning("Phonebook with ID %s not found on Fritz!Box", phonebook_id) diff --git a/homeassistant/components/sensor/qnap.py b/homeassistant/components/sensor/qnap.py index 74fc78a4a211..3caebad20071 100644 --- a/homeassistant/components/sensor/qnap.py +++ b/homeassistant/components/sensor/qnap.py @@ -206,7 +206,7 @@ def update(self): self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.exception("Failed to fetch QNAP stats from the NAS") diff --git a/homeassistant/components/sensor/synologydsm.py b/homeassistant/components/sensor/synologydsm.py index bfd1b17db084..f5a41c7b8ceb 100644 --- a/homeassistant/components/sensor/synologydsm.py +++ b/homeassistant/components/sensor/synologydsm.py @@ -143,7 +143,7 @@ def __init__(self, host, port, username, password, temp_unit): try: self._api = SynologyDSM(host, port, username, password) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.error("Error setting up Synology DSM") # Will be updated when update() gets called. diff --git a/homeassistant/components/spc.py b/homeassistant/components/spc.py index 60d191184e17..72477a5a65f1 100644 --- a/homeassistant/components/spc.py +++ b/homeassistant/components/spc.py @@ -151,7 +151,7 @@ def _ws_process_message(message, async_callback, *args): "Unsuccessful websocket message delivered, ignoring: %s", message) try: yield from async_callback(message['data']['sia'], *args) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.exception("Exception in callback, ignoring") diff --git a/homeassistant/monkey_patch.py b/homeassistant/monkey_patch.py index 940131d01f83..5aa051f2bb5e 100644 --- a/homeassistant/monkey_patch.py +++ b/homeassistant/monkey_patch.py @@ -37,7 +37,7 @@ def add(self, other): asyncio.tasks.Task._all_tasks = IgnoreCalls() try: del asyncio.tasks.Task.__del__ - except Exception: + except: # noqa: E722 pass diff --git a/tests/components/emulated_hue/test_upnp.py b/tests/components/emulated_hue/test_upnp.py index da40bf37cce9..b30329544310 100644 --- a/tests/components/emulated_hue/test_upnp.py +++ b/tests/components/emulated_hue/test_upnp.py @@ -89,7 +89,7 @@ def test_description_xml(self): # Make sure the XML is parsable try: ET.fromstring(result.text) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except self.fail('description.xml is not valid XML!') def test_create_username(self): diff --git a/tests/components/test_system_log.py b/tests/components/test_system_log.py index 85b763c0fbde..6ad68f2274a8 100644 --- a/tests/components/test_system_log.py +++ b/tests/components/test_system_log.py @@ -34,7 +34,7 @@ def get_error_log(hass, test_client, expected_count): def _generate_and_log_exception(exception, log): try: raise Exception(exception) - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 # pylint: disable=bare-except _LOGGER.exception(log)