From e7bd93b4b02508a12477f445927991fb6616ac1b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Sep 2020 12:12:40 +0200 Subject: [PATCH] Bump pylint from 2.5.3 to 2.6.0 (#1262) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Otto Winter --- esphome/api/client.py | 8 ++++---- esphome/automation.py | 1 + esphome/components/binary_sensor/__init__.py | 1 + esphome/components/font/__init__.py | 4 ++-- esphome/components/http_request/__init__.py | 4 ++-- esphome/components/pn532/binary_sensor.py | 4 ++-- esphome/components/stepper/__init__.py | 2 ++ esphome/components/time/__init__.py | 2 ++ esphome/components/wifi/wpa2_eap.py | 4 ++-- esphome/config.py | 4 ++-- esphome/config_validation.py | 16 ++++++++++++---- esphome/espota2.py | 12 ++++++------ esphome/helpers.py | 20 ++++++++++---------- esphome/mqtt.py | 2 +- esphome/voluptuous_schema.py | 1 + esphome/yaml_util.py | 3 ++- requirements_test.txt | 2 +- 17 files changed, 53 insertions(+), 37 deletions(-) diff --git a/esphome/api/client.py b/esphome/api/client.py index fcea90e3b4..a32c239819 100644 --- a/esphome/api/client.py +++ b/esphome/api/client.py @@ -181,7 +181,7 @@ class APIClient(threading.Thread): self._address) _LOGGER.warning("(If this error persists, please set a static IP address: " "https://esphome.io/components/wifi.html#manual-ips)") - raise APIConnectionError(err) + raise APIConnectionError(err) from err _LOGGER.info("Connecting to %s:%s (%s)", self._address, self._port, ip) self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -346,12 +346,12 @@ class APIClient(threading.Thread): raise APIConnectionError("No socket!") try: val = self._socket.recv(amount - len(ret)) - except AttributeError: - raise APIConnectionError("Socket was closed") + except AttributeError as err: + raise APIConnectionError("Socket was closed") from err except socket.timeout: continue except OSError as err: - raise APIConnectionError(f"Error while receiving data: {err}") + raise APIConnectionError(f"Error while receiving data: {err}") from err ret += val return ret diff --git a/esphome/automation.py b/esphome/automation.py index 5df884e7c2..4b5e39b0f5 100644 --- a/esphome/automation.py +++ b/esphome/automation.py @@ -84,6 +84,7 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False): return cv.Schema([schema])(value) except cv.Invalid as err2: if 'extra keys not allowed' in str(err2) and len(err2.path) == 2: + # pylint: disable=raise-missing-from raise err if 'Unable to find action' in str(err): raise err2 diff --git a/esphome/components/binary_sensor/__init__.py b/esphome/components/binary_sensor/__init__.py index 8361ee8004..753010310c 100644 --- a/esphome/components/binary_sensor/__init__.py +++ b/esphome/components/binary_sensor/__init__.py @@ -104,6 +104,7 @@ def parse_multi_click_timing_str(value): try: state = cv.boolean(parts[0]) except cv.Invalid: + # pylint: disable=raise-missing-from raise cv.Invalid("First word must either be ON or OFF, not {}".format(parts[0])) if parts[1] != 'for': diff --git a/esphome/components/font/__init__.py b/esphome/components/font/__init__.py index 5b19dc74e0..ee50b10830 100644 --- a/esphome/components/font/__init__.py +++ b/esphome/components/font/__init__.py @@ -42,9 +42,9 @@ def validate_glyphs(value): def validate_pillow_installed(value): try: import PIL - except ImportError: + except ImportError as err: raise cv.Invalid("Please install the pillow python package to use this feature. " - "(pip install pillow)") + "(pip install pillow)") from err if PIL.__version__[0] < '4': raise cv.Invalid("Please update your pillow installation to at least 4.0.x. " diff --git a/esphome/components/http_request/__init__.py b/esphome/components/http_request/__init__.py index b003736d89..f7ec3cdbbf 100644 --- a/esphome/components/http_request/__init__.py +++ b/esphome/components/http_request/__init__.py @@ -43,8 +43,8 @@ def validate_url(value): value = cv.string(value) try: parsed = list(urlparse.urlparse(value)) - except Exception: - raise cv.Invalid('Invalid URL') + except Exception as err: + raise cv.Invalid('Invalid URL') from err if not parsed[0] or not parsed[1]: raise cv.Invalid('URL must have a URL scheme and host') diff --git a/esphome/components/pn532/binary_sensor.py b/esphome/components/pn532/binary_sensor.py index 1c5e220fa6..46a7ac03c8 100644 --- a/esphome/components/pn532/binary_sensor.py +++ b/esphome/components/pn532/binary_sensor.py @@ -18,8 +18,8 @@ def validate_uid(value): "long.") try: x = int(x, 16) - except ValueError: - raise cv.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.") + except ValueError as err: + raise cv.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.") from err if x < 0 or x > 255: raise cv.Invalid("Valid values for UID parts (separated by '-') are 00 to FF") return value diff --git a/esphome/components/stepper/__init__.py b/esphome/components/stepper/__init__.py index e8d6acbd1c..c61aaa7fc9 100644 --- a/esphome/components/stepper/__init__.py +++ b/esphome/components/stepper/__init__.py @@ -28,6 +28,7 @@ def validate_acceleration(value): try: value = float(value) except ValueError: + # pylint: disable=raise-missing-from raise cv.Invalid(f"Expected acceleration as floating point number, got {value}") if value <= 0: @@ -48,6 +49,7 @@ def validate_speed(value): try: value = float(value) except ValueError: + # pylint: disable=raise-missing-from raise cv.Invalid(f"Expected speed as floating point number, got {value}") if value <= 0: diff --git a/esphome/components/time/__init__.py b/esphome/components/time/__init__.py index 49ed53c47e..ddbc1d6093 100644 --- a/esphome/components/time/__init__.py +++ b/esphome/components/time/__init__.py @@ -138,6 +138,7 @@ def _parse_cron_int(value, special_mapping, message): try: return int(value) except ValueError: + # pylint: disable=raise-missing-from raise cv.Invalid(message.format(value)) @@ -158,6 +159,7 @@ def _parse_cron_part(part, min_value, max_value, special_mapping): try: repeat_n = int(repeat) except ValueError: + # pylint: disable=raise-missing-from raise cv.Invalid("Repeat for '/' time expression must be an integer, got {}" .format(repeat)) return set(range(offset_n, max_value + 1, repeat_n)) diff --git a/esphome/components/wifi/wpa2_eap.py b/esphome/components/wifi/wpa2_eap.py index 8bf50598b0..54195c852b 100644 --- a/esphome/components/wifi/wpa2_eap.py +++ b/esphome/components/wifi/wpa2_eap.py @@ -18,9 +18,9 @@ _LOGGER = logging.getLogger(__name__) def validate_cryptography_installed(): try: import cryptography - except ImportError: + except ImportError as err: raise cv.Invalid("This settings requires the cryptography python package. " - "Please install it with `pip install cryptography`") + "Please install it with `pip install cryptography`") from err if cryptography.__version__[0] < '2': raise cv.Invalid("Please update your python cryptography installation to least 2.x " diff --git a/esphome/config.py b/esphome/config.py index 85f48c64b7..0484414929 100644 --- a/esphome/config.py +++ b/esphome/config.py @@ -675,7 +675,7 @@ def _load_config(command_line_substitutions): try: config = yaml_util.load_yaml(CORE.config_path) except EsphomeError as e: - raise InvalidYAMLError(e) + raise InvalidYAMLError(e) from e CORE.raw_config = config try: @@ -693,7 +693,7 @@ def load_config(command_line_substitutions): try: return _load_config(command_line_substitutions) except vol.Invalid as err: - raise EsphomeError(f"Error while parsing config: {err}") + raise EsphomeError(f"Error while parsing config: {err}") from err def line_info(obj, highlight=True): diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 3fb2b4827c..aaa822c587 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -224,6 +224,7 @@ def int_(value): try: return int(value, base) except ValueError: + # pylint: disable=raise-missing-from raise Invalid(f"Expected integer, but cannot parse {value} as an integer") @@ -423,6 +424,7 @@ def time_period_str_colon(value): try: parsed = [int(x) for x in value.split(':')] except ValueError: + # pylint: disable=raise-missing-from raise Invalid(TIME_PERIOD_ERROR.format(value)) if len(parsed) == 2: @@ -527,6 +529,7 @@ def time_of_day(value): try: date = datetime.strptime(value, '%H:%M:%S %p') except ValueError: + # pylint: disable=raise-missing-from raise Invalid(f"Invalid time of day: {err}") return { @@ -548,6 +551,7 @@ def mac_address(value): try: parts_int.append(int(part, 16)) except ValueError: + # pylint: disable=raise-missing-from raise Invalid("MAC Address parts must be hexadecimal values from 00 to FF") return core.MACAddress(*parts_int) @@ -565,6 +569,7 @@ def bind_key(value): try: parts_int.append(int(part, 16)) except ValueError: + # pylint: disable=raise-missing-from raise Invalid("Bind key must be hex values from 00 to FF") return ''.join(f'{part:02X}' for part in parts_int) @@ -686,8 +691,8 @@ def domain(value): return value try: return str(ipv4(value)) - except Invalid: - raise Invalid(f"Invalid domain: {value}") + except Invalid as err: + raise Invalid(f"Invalid domain: {value}") from err def domain_name(value): @@ -739,8 +744,8 @@ def _valid_topic(value): value = string(value) try: raw_value = value.encode('utf-8') - except UnicodeError: - raise Invalid("MQTT topic name/filter must be valid UTF-8 string.") + except UnicodeError as err: + raise Invalid("MQTT topic name/filter must be valid UTF-8 string.") from err if not raw_value: raise Invalid("MQTT topic name/filter must not be empty.") if len(raw_value) > 65535: @@ -792,6 +797,7 @@ def mqtt_qos(value): try: value = int(value) except (TypeError, ValueError): + # pylint: disable=raise-missing-from raise Invalid(f"MQTT Quality of Service must be integer, got {value}") return one_of(0, 1, 2)(value) @@ -836,6 +842,7 @@ def possibly_negative_percentage(value): else: value = float(value) except ValueError: + # pylint: disable=raise-missing-from raise Invalid("invalid number") if value > 1: msg = "Percentage must not be higher than 100%." @@ -1006,6 +1013,7 @@ def dimensions(value): try: width, height = int(value[0]), int(value[1]) except ValueError: + # pylint: disable=raise-missing-from raise Invalid("Width and height dimensions must be integers") if width <= 0 or height <= 0: raise Invalid("Width and height must at least be 1") diff --git a/esphome/espota2.py b/esphome/espota2.py index edfa4e63e6..a1408a7d44 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -83,19 +83,19 @@ def receive_exactly(sock, amount, msg, expect, decode=True): try: data += recv_decode(sock, 1, decode=decode) except OSError as err: - raise OTAError(f"Error receiving acknowledge {msg}: {err}") + raise OTAError(f"Error receiving acknowledge {msg}: {err}") from err try: check_error(data, expect) except OTAError as err: sock.close() - raise OTAError(f"Error {msg}: {err}") + raise OTAError(f"Error {msg}: {err}") from err while len(data) < amount: try: data += recv_decode(sock, amount - len(data), decode=decode) except OSError as err: - raise OTAError(f"Error receiving {msg}: {err}") + raise OTAError(f"Error receiving {msg}: {err}") from err return data @@ -151,7 +151,7 @@ def send_check(sock, data, msg): sock.sendall(data) except OSError as err: - raise OTAError(f"Error sending {msg}: {err}") + raise OTAError(f"Error sending {msg}: {err}") from err def perform_ota(sock, password, file_handle, filename): @@ -226,7 +226,7 @@ def perform_ota(sock, password, file_handle, filename): sock.sendall(chunk) except OSError as err: sys.stderr.write('\n') - raise OTAError(f"Error sending data: {err}") + raise OTAError(f"Error sending data: {err}") from err progress.update(offset / float(file_size)) progress.done() @@ -259,7 +259,7 @@ def run_ota_impl_(remote_host, remote_port, password, filename): remote_host) _LOGGER.error("(If this error persists, please set a static IP address: " "https://esphome.io/components/wifi.html#manual-ips)") - raise OTAError(err) + raise OTAError(err) from err _LOGGER.info(" -> %s", ip) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/esphome/helpers.py b/esphome/helpers.py index b30ace89d2..1389804fd9 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -89,7 +89,7 @@ def mkdir_p(path): pass else: from esphome.core import EsphomeError - raise EsphomeError(f"Error creating directories {path}: {err}") + raise EsphomeError(f"Error creating directories {path}: {err}") from err def is_ip_address(host): @@ -110,13 +110,13 @@ def _resolve_with_zeroconf(host): try: zc = Zeroconf() - except Exception: + except Exception as err: raise EsphomeError("Cannot start mDNS sockets, is this a docker container without " - "host network mode?") + "host network mode?") from err try: info = zc.resolve_host(host + '.') except Exception as err: - raise EsphomeError(f"Error resolving mDNS hostname: {err}") + raise EsphomeError(f"Error resolving mDNS hostname: {err}") from err finally: zc.close() if info is None: @@ -142,7 +142,7 @@ def resolve_ip_address(host): except OSError as err: errs.append(str(err)) raise EsphomeError("Error resolving IP address: {}" - "".format(', '.join(errs))) + "".format(', '.join(errs))) from err def get_bool_env(var, default=False): @@ -165,10 +165,10 @@ def read_file(path): return f_handle.read() except OSError as err: from esphome.core import EsphomeError - raise EsphomeError(f"Error reading file {path}: {err}") + raise EsphomeError(f"Error reading file {path}: {err}") from err except UnicodeDecodeError as err: from esphome.core import EsphomeError - raise EsphomeError(f"Error reading file {path}: {err}") + raise EsphomeError(f"Error reading file {path}: {err}") from err def _write_file(path: Union[Path, str], text: Union[str, bytes]): @@ -205,9 +205,9 @@ def _write_file(path: Union[Path, str], text: Union[str, bytes]): def write_file(path: Union[Path, str], text: str): try: _write_file(path, text) - except OSError: + except OSError as err: from esphome.core import EsphomeError - raise EsphomeError(f"Could not write file at {path}") + raise EsphomeError(f"Could not write file at {path}") from err def write_file_if_changed(path: Union[Path, str], text: str): @@ -230,7 +230,7 @@ def copy_file_if_changed(src, dst): shutil.copy(src, dst) except OSError as err: from esphome.core import EsphomeError - raise EsphomeError(f"Error copying file {src} to {dst}: {err}") + raise EsphomeError(f"Error copying file {src} to {dst}: {err}") from err def list_starts_with(list_, sub): diff --git a/esphome/mqtt.py b/esphome/mqtt.py index cbcf067c44..499ccbe7f1 100644 --- a/esphome/mqtt.py +++ b/esphome/mqtt.py @@ -67,7 +67,7 @@ def initialize(config, subscriptions, on_message, username, password, client_id) port = int(config[CONF_MQTT][CONF_PORT]) client.connect(host, port) except OSError as err: - raise EsphomeError(f"Cannot connect to MQTT broker: {err}") + raise EsphomeError(f"Cannot connect to MQTT broker: {err}") from err try: client.loop_forever() diff --git a/esphome/voluptuous_schema.py b/esphome/voluptuous_schema.py index ce13f0ceb0..d10801fb95 100644 --- a/esphome/voluptuous_schema.py +++ b/esphome/voluptuous_schema.py @@ -32,6 +32,7 @@ class _Schema(vol.Schema): try: res = extra(res) except vol.Invalid as err: + # pylint: disable=raise-missing-from raise ensure_multiple_invalid(err) return res diff --git a/esphome/yaml_util.py b/esphome/yaml_util.py index 053fba6274..857a986538 100644 --- a/esphome/yaml_util.py +++ b/esphome/yaml_util.py @@ -126,6 +126,7 @@ class ESPHomeLoader(yaml.SafeLoader): # pylint: disable=too-many-ancestors try: hash(key) except TypeError: + # pylint: disable=raise-missing-from raise yaml.constructor.ConstructorError( f'Invalid key "{key}" (not hashable)', key_node.start_mark) @@ -297,7 +298,7 @@ def _load_yaml_internal(fname): try: return loader.get_single_data() or OrderedDict() except yaml.YAMLError as exc: - raise EsphomeError(exc) + raise EsphomeError(exc) from exc finally: loader.dispose() diff --git a/requirements_test.txt b/requirements_test.txt index 252e985767..b16607be97 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,4 +1,4 @@ -pylint==2.5.3 +pylint==2.6.0 flake8==3.8.3 pillow>4.0.0 cryptography>=2.0.0,<4