From 54337befc262f7935b61c2b9f970db0c66c8d74f Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Tue, 31 Aug 2021 14:00:58 +1200 Subject: [PATCH] Fix some lint errors in pylint 2.10.2 (#2226) --- esphome/components/mcp23xxx_base/__init__.py | 3 ++- esphome/components/web_server/__init__.py | 4 ++-- esphome/config_validation.py | 7 ++++--- esphome/dashboard/dashboard.py | 6 ++++-- esphome/helpers.py | 10 +++++----- esphome/writer.py | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/esphome/components/mcp23xxx_base/__init__.py b/esphome/components/mcp23xxx_base/__init__.py index 019b7c7e64..c22d377b3c 100644 --- a/esphome/components/mcp23xxx_base/__init__.py +++ b/esphome/components/mcp23xxx_base/__init__.py @@ -91,7 +91,7 @@ async def mcp23xxx_pin_to_code(config): # BEGIN Removed pin schemas below to show error in configuration -# TODO remove in 1.19.0 +# TODO remove in 2022.5.0 for id in ["mcp23008", "mcp23s08", "mcp23017", "mcp23s17"]: PIN_SCHEMA = cv.Schema( @@ -110,6 +110,7 @@ for id in ["mcp23008", "mcp23s08", "mcp23017", "mcp23s17"]: } ) + # pylint: disable=cell-var-from-loop @pins.PIN_SCHEMA_REGISTRY.register(id, (PIN_SCHEMA, PIN_SCHEMA)) def pin_to_code(config): pass diff --git a/esphome/components/web_server/__init__.py b/esphome/components/web_server/__init__.py index ca3a60f43f..7f17767657 100644 --- a/esphome/components/web_server/__init__.py +++ b/esphome/components/web_server/__init__.py @@ -62,10 +62,10 @@ async def to_code(config): if CONF_CSS_INCLUDE in config: cg.add_define("WEBSERVER_CSS_INCLUDE") path = CORE.relative_config_path(config[CONF_CSS_INCLUDE]) - with open(path, "r") as myfile: + with open(file=path, mode="r", encoding="utf-8") as myfile: cg.add(var.set_css_include(myfile.read())) if CONF_JS_INCLUDE in config: cg.add_define("WEBSERVER_JS_INCLUDE") path = CORE.relative_config_path(config[CONF_JS_INCLUDE]) - with open(path, "r") as myfile: + with open(file=path, mode="r", encoding="utf-8") as myfile: cg.add(var.set_js_include(myfile.read())) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 61ef7d2f9f..4df65a38e3 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -836,10 +836,11 @@ pressure = float_with_unit("pressure", "(bar|Bar)", optional_unit=True) def temperature(value): + err = None try: return _temperature_c(value) - except Invalid as orig_err: # noqa - pass + except Invalid as orig_err: + err = orig_err try: kelvin = _temperature_k(value) @@ -853,7 +854,7 @@ def temperature(value): except Invalid: pass - raise orig_err # noqa + raise err _color_temperature_mireds = float_with_unit("Color Temperature", r"(mireds|Mireds)") diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index ea55ea3b18..8016bf7bbd 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -600,7 +600,7 @@ class EditRequestHandler(BaseHandler): content = "" if os.path.isfile(filename): # pylint: disable=no-value-for-parameter - with open(filename, "r") as f: + with open(file=filename, mode="r", encoding="utf-8") as f: content = f.read() self.write(content) @@ -608,7 +608,9 @@ class EditRequestHandler(BaseHandler): @bind_config def post(self, configuration=None): # pylint: disable=no-value-for-parameter - with open(settings.rel_path(configuration), "wb") as f: + with open( + file=settings.rel_path(configuration), mode="wb", encoding="utf-8" + ) as f: f.write(self.request.body) self.set_status(200) diff --git a/esphome/helpers.py b/esphome/helpers.py index ad7b8272b2..c766cc1ac7 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -276,11 +276,11 @@ def file_compare(path1: os.PathLike, path2: os.PathLike) -> bool: # A dict of types that need to be converted to heaptypes before a class can be added # to the object _TYPE_OVERLOADS = { - int: type("EInt", (int,), dict()), - float: type("EFloat", (float,), dict()), - str: type("EStr", (str,), dict()), - dict: type("EDict", (str,), dict()), - list: type("EList", (list,), dict()), + int: type("EInt", (int,), {}), + float: type("EFloat", (float,), {}), + str: type("EStr", (str,), {}), + dict: type("EDict", (str,), {}), + list: type("EList", (list,), {}), } # cache created classes here diff --git a/esphome/writer.py b/esphome/writer.py index 641ae9b3cc..09ed284173 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -481,5 +481,5 @@ GITIGNORE_CONTENT = """# Gitignore settings for ESPHome def write_gitignore(): path = CORE.relative_config_path(".gitignore") if not os.path.isfile(path): - with open(path, "w") as f: + with open(file=path, mode="w", encoding="utf-8") as f: f.write(GITIGNORE_CONTENT)