From f28c3273c29b8071fa7d2abeea00b280f195c144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi> Date: Tue, 13 Oct 2020 03:17:30 +0300 Subject: [PATCH] Upgrade mypy to 0.790 (#41595) --- homeassistant/components/calendar/__init__.py | 5 +++-- homeassistant/helpers/config_validation.py | 8 ++++---- homeassistant/helpers/entity_platform.py | 2 +- homeassistant/helpers/location.py | 3 ++- homeassistant/scripts/macos/__init__.py | 4 ++-- homeassistant/util/__init__.py | 2 +- homeassistant/util/logging.py | 2 +- requirements_test.txt | 2 +- setup.cfg | 1 + 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index c0e94defae5..61fd3a3d68f 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -2,6 +2,7 @@ from datetime import timedelta import logging import re +from typing import Dict, List, cast from aiohttp import web @@ -207,10 +208,10 @@ class CalendarListView(http.HomeAssistantView): async def get(self, request: web.Request) -> web.Response: """Retrieve calendar list.""" hass = request.app["hass"] - calendar_list = [] + calendar_list: List[Dict[str, str]] = [] for entity in self.component.entities: state = hass.states.get(entity.entity_id) calendar_list.append({"name": state.name, "entity_id": entity.entity_id}) - return self.json(sorted(calendar_list, key=lambda x: x["name"])) + return self.json(sorted(calendar_list, key=lambda x: cast(str, x["name"]))) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 0b636ea5699..e41e26e5e0f 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -527,8 +527,8 @@ def template(value: Optional[Any]) -> template_helper.Template: template_value = template_helper.Template(str(value)) # type: ignore try: - template_value.ensure_valid() - return cast(template_helper.Template, template_value) + template_value.ensure_valid() # type: ignore[no-untyped-call] + return template_value except TemplateError as ex: raise vol.Invalid(f"invalid template ({ex})") from ex @@ -545,8 +545,8 @@ def dynamic_template(value: Optional[Any]) -> template_helper.Template: template_value = template_helper.Template(str(value)) # type: ignore try: - template_value.ensure_valid() - return cast(template_helper.Template, template_value) + template_value.ensure_valid() # type: ignore[no-untyped-call] + return template_value except TemplateError as ex: raise vol.Invalid(f"invalid template ({ex})") from ex diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 39b09cef193..c971fa1ceb5 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -138,7 +138,7 @@ class EntityPlatform: # This should not be replaced with hass.async_add_job because # we don't want to track this task in case it blocks startup. - return hass.loop.run_in_executor( + return hass.loop.run_in_executor( # type: ignore[return-value] None, platform.setup_platform, # type: ignore hass, diff --git a/homeassistant/helpers/location.py b/homeassistant/helpers/location.py index 92af08bbd00..856c5c4d8e3 100644 --- a/homeassistant/helpers/location.py +++ b/homeassistant/helpers/location.py @@ -46,7 +46,8 @@ def closest( state.attributes.get(ATTR_LONGITUDE), latitude, longitude, - ), + ) + or 0, ) diff --git a/homeassistant/scripts/macos/__init__.py b/homeassistant/scripts/macos/__init__.py index b1c91001351..e6d128fa846 100644 --- a/homeassistant/scripts/macos/__init__.py +++ b/homeassistant/scripts/macos/__init__.py @@ -15,8 +15,8 @@ def install_osx(): template_path = os.path.join(os.path.dirname(__file__), "launchd.plist") - with open(template_path, encoding="utf-8") as inp: - plist = inp.read() + with open(template_path, encoding="utf-8") as tinp: + plist = tinp.read() plist = plist.replace("$HASS_PATH$", hass_path) plist = plist.replace("$USER$", user) diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index 135de94a513..db1bbaa9993 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -44,7 +44,7 @@ def sanitize_path(path: str) -> str: def slugify(text: str, *, separator: str = "_") -> str: """Slugify a given text.""" - return unicode_slug.slugify(text, separator=separator) # type: ignore + return unicode_slug.slugify(text, separator=separator) def repr_helper(inp: Any) -> str: diff --git a/homeassistant/util/logging.py b/homeassistant/util/logging.py index db40412cbf2..2f202165550 100644 --- a/homeassistant/util/logging.py +++ b/homeassistant/util/logging.py @@ -172,7 +172,7 @@ def async_create_catching_coro(target: Coroutine) -> Coroutine: wrapped_target = catch_log_coro_exception( target, lambda *args: "Exception in {} called from\n {}".format( - target.__name__, # type: ignore + target.__name__, "".join(traceback.format_list(trace[:-1])), ), ) diff --git a/requirements_test.txt b/requirements_test.txt index d07fa5a6421..3ec0782ca70 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -9,7 +9,7 @@ codecov==2.1.10 coverage==5.3 jsonpickle==1.4.1 mock-open==1.4.0 -mypy==0.782 +mypy==0.790 pre-commit==2.7.1 pylint==2.6.0 astroid==2.4.2 diff --git a/setup.cfg b/setup.cfg index 5b3d00fab87..8286e58c7cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ ignore = [mypy] python_version = 3.7 +show_error_codes = true ignore_errors = true follow_imports = silent ignore_missing_imports = true -- GitLab