From 381d423fecd95f2b901f3ca1fa277746e7756c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 19 Oct 2019 21:35:57 +0300 Subject: [PATCH] Upgrade mypy to 0.740 (#27913) * Upgrade mypy to 0.740 http://mypy-lang.blogspot.com/2019/10/mypy-0740-released.html * Type hint additions * Type fixes * Remove no longer needed type ignores and casts * Disable untyped definition checks in bunch of files --- homeassistant/auth/__init__.py | 4 ++-- homeassistant/components/cover/__init__.py | 2 +- homeassistant/components/group/__init__.py | 2 +- homeassistant/components/group/cover.py | 5 +++-- homeassistant/components/group/light.py | 1 + homeassistant/components/group/notify.py | 2 +- homeassistant/components/sun/__init__.py | 2 +- homeassistant/components/switch/light.py | 2 +- homeassistant/components/websocket_api/http.py | 7 ++++--- homeassistant/components/websocket_api/sensor.py | 2 +- homeassistant/components/zone/config_flow.py | 2 +- homeassistant/config_entries.py | 4 ++-- homeassistant/helpers/config_entry_flow.py | 2 +- homeassistant/helpers/storage.py | 1 + homeassistant/util/location.py | 4 ++-- requirements_test.txt | 2 +- requirements_test_all.txt | 2 +- 17 files changed, 25 insertions(+), 21 deletions(-) diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 64391debc10..921bec71e78 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -45,7 +45,7 @@ async def auth_manager_from_config( ) ) else: - providers = () + providers = [] # So returned auth providers are in same order as config provider_hash: _ProviderDict = OrderedDict() for provider in providers: @@ -57,7 +57,7 @@ async def auth_manager_from_config( *(auth_mfa_module_from_config(hass, config) for config in module_configs) ) else: - modules = () + modules = [] # So returned auth modules are in same order as config module_hash: _MfaModuleDict = OrderedDict() for module in modules: diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 8d2b4430fe1..cfac143a5d8 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -34,7 +34,7 @@ from homeassistant.const import ( ) -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index 39574a2b03b..29126c82d44 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -36,7 +36,7 @@ from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA from homeassistant.helpers.typing import HomeAssistantType -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs DOMAIN = "group" diff --git a/homeassistant/components/group/cover.py b/homeassistant/components/group/cover.py index c5200082f2f..f7a9643e5c8 100644 --- a/homeassistant/components/group/cover.py +++ b/homeassistant/components/group/cover.py @@ -44,6 +44,7 @@ from homeassistant.components.cover import ( # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs +# mypy: no-check-untyped-defs _LOGGER = logging.getLogger(__name__) @@ -74,7 +75,7 @@ class CoverGroup(CoverDevice): """Initialize a CoverGroup entity.""" self._name = name self._is_closed = False - self._cover_position = 100 + self._cover_position: Optional[int] = 100 self._tilt_position = None self._supported_features = 0 self._assumed_state = True @@ -178,7 +179,7 @@ class CoverGroup(CoverDevice): return self._is_closed @property - def current_cover_position(self): + def current_cover_position(self) -> Optional[int]: """Return current position for all covers.""" return self._cover_position diff --git a/homeassistant/components/group/light.py b/homeassistant/components/group/light.py index e77c858fc02..85804552494 100644 --- a/homeassistant/components/group/light.py +++ b/homeassistant/components/group/light.py @@ -45,6 +45,7 @@ from homeassistant.components.light import ( # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs +# mypy: no-check-untyped-defs _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/group/notify.py b/homeassistant/components/group/notify.py index 2ffb7fea049..e17990690fa 100644 --- a/homeassistant/components/group/notify.py +++ b/homeassistant/components/group/notify.py @@ -18,7 +18,7 @@ from homeassistant.components.notify import ( ) -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/sun/__init__.py b/homeassistant/components/sun/__init__.py index 7d883e273e5..e848449e61e 100644 --- a/homeassistant/components/sun/__init__.py +++ b/homeassistant/components/sun/__init__.py @@ -18,7 +18,7 @@ from homeassistant.helpers.sun import ( from homeassistant.util import dt as dt_util -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/switch/light.py b/homeassistant/components/switch/light.py index 8f3b5d87f8c..b0abf957991 100644 --- a/homeassistant/components/switch/light.py +++ b/homeassistant/components/switch/light.py @@ -21,7 +21,7 @@ from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.components.light import PLATFORM_SCHEMA, Light -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/websocket_api/http.py b/homeassistant/components/websocket_api/http.py index 08a0430ee2a..be1830aa07b 100644 --- a/homeassistant/components/websocket_api/http.py +++ b/homeassistant/components/websocket_api/http.py @@ -2,6 +2,7 @@ import asyncio from contextlib import suppress import logging +from typing import Optional from aiohttp import web, WSMsgType import async_timeout @@ -25,7 +26,7 @@ from .error import Disconnect from .messages import error_message -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs class WebsocketAPIView(HomeAssistantView): @@ -47,7 +48,7 @@ class WebSocketHandler: """Initialize an active connection.""" self.hass = hass self.request = request - self.wsock = None + self.wsock: Optional[web.WebSocketResponse] = None self._to_write: asyncio.Queue = asyncio.Queue(maxsize=MAX_PENDING_MSG) self._handle_task = None self._writer_task = None @@ -115,7 +116,7 @@ class WebSocketHandler: # Py3.7+ if hasattr(asyncio, "current_task"): # pylint: disable=no-member - self._handle_task = asyncio.current_task() # type: ignore + self._handle_task = asyncio.current_task() else: self._handle_task = asyncio.Task.current_task() diff --git a/homeassistant/components/websocket_api/sensor.py b/homeassistant/components/websocket_api/sensor.py index 20a6a90860b..f8f1257aefc 100644 --- a/homeassistant/components/websocket_api/sensor.py +++ b/homeassistant/components/websocket_api/sensor.py @@ -10,7 +10,7 @@ from .const import ( ) -# mypy: allow-untyped-calls, allow-untyped-defs +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): diff --git a/homeassistant/components/zone/config_flow.py b/homeassistant/components/zone/config_flow.py index d23fb5a4757..39633754772 100644 --- a/homeassistant/components/zone/config_flow.py +++ b/homeassistant/components/zone/config_flow.py @@ -20,7 +20,7 @@ from homeassistant.util import slugify from .const import CONF_PASSIVE, DOMAIN, HOME_ZONE -# mypy: allow-untyped-defs +# mypy: allow-untyped-defs, no-check-untyped-defs @callback diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index f8c7c7a9da1..aee15d6c0ce 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -15,7 +15,7 @@ from homeassistant.setup import async_setup_component, async_process_deps_reqs from homeassistant.util.decorator import Registry from homeassistant.helpers import entity_registry -# mypy: allow-untyped-defs +# mypy: allow-untyped-defs, no-check-untyped-defs _LOGGER = logging.getLogger(__name__) _UNDEF = object() @@ -676,7 +676,7 @@ async def _old_conf_migrator(old_config): class ConfigFlow(data_entry_flow.FlowHandler): """Base class for config flows with some helpers.""" - def __init_subclass__(cls, domain=None, **kwargs): + def __init_subclass__(cls, domain: Optional[str] = None, **kwargs: Any) -> None: """Initialize a subclass, register if possible.""" super().__init_subclass__(**kwargs) # type: ignore if domain is not None: diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 374ef795846..7a1512957a2 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -3,7 +3,7 @@ from typing import Callable, Awaitable, Union from homeassistant import config_entries from .typing import HomeAssistantType -# mypy: allow-untyped-defs +# mypy: allow-untyped-defs, no-check-untyped-defs DiscoveryFunctionType = Callable[[], Union[Awaitable[bool], bool]] diff --git a/homeassistant/helpers/storage.py b/homeassistant/helpers/storage.py index cd99a47cf57..72458d24c82 100644 --- a/homeassistant/helpers/storage.py +++ b/homeassistant/helpers/storage.py @@ -13,6 +13,7 @@ from homeassistant.helpers.event import async_call_later # mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any +# mypy: no-check-untyped-defs STORAGE_DIR = ".storage" _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/util/location.py b/homeassistant/util/location.py index f81c40a52bb..7c61a8ab1e9 100644 --- a/homeassistant/util/location.py +++ b/homeassistant/util/location.py @@ -6,7 +6,7 @@ detect_location_info and elevation are mocked by default during tests. import asyncio import collections import math -from typing import Any, Optional, Tuple, Dict, cast +from typing import Any, Optional, Tuple, Dict import aiohttp @@ -159,7 +159,7 @@ def vincenty( if miles: s *= MILES_PER_KILOMETER # kilometers to miles - return round(cast(float, s), 6) + return round(s, 6) async def _get_ipapi(session: aiohttp.ClientSession) -> Optional[Dict[str, Any]]: diff --git a/requirements_test.txt b/requirements_test.txt index e491d5ea42a..7af2ec0dde3 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -9,7 +9,7 @@ codecov==2.0.15 flake8-docstrings==1.5.0 flake8==3.7.8 mock-open==1.3.1 -mypy==0.730 +mypy==0.740 pre-commit==1.18.3 pydocstyle==4.0.1 pylint==2.4.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 93d639dadd9..dc6267be6a9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -10,7 +10,7 @@ codecov==2.0.15 flake8-docstrings==1.5.0 flake8==3.7.8 mock-open==1.3.1 -mypy==0.730 +mypy==0.740 pre-commit==1.18.3 pydocstyle==4.0.1 pylint==2.4.3