diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index c0e94defae524f644e264a4d5d139ceb57531edc..61fd3a3d68f5abf7e6b3917c8e647c75cb7f2dd8 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 0b636ea56993b4d747b83a61de4a7b4e80c501a0..e41e26e5e0ff1d576d51b48ba7556be58853980e 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 39b09cef193986db2f411d2f40a4e9b5995e4418..c971fa1ceb56a5ab862a1f7b019949621057267c 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 92af08bbd004a8ab9177939eda5be4afa4bf1ae4..856c5c4d8e3afe80231e343d3715cc33d5a2ea89 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 b1c910013517ac8eba04432cc31484be74ed082c..e6d128fa8467d68c54f0c1300f650d91eb9ac339 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 135de94a513197ca60b3a5c93dd2f42d014151ec..db1bbaa99931e01c68959da953f9269f2f283a55 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 db40412cbf2f57ace8ab7f89d4cf0b772a40759c..2f202165550bf7a2a6ed7b2888cf38385769e0dd 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 d07fa5a64217e470522e59450a535c154fab00ae..3ec0782ca706e5370a43b3bde891eb0d83c1a025 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 5b3d00fab879c4bb0a04527267ba5795dc4cfe45..8286e58c7cfeb7a56f7852612baec85f6971c01f 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