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
This commit is contained in:
Ville Skyttä 2019-10-19 21:35:57 +03:00 committed by Paulus Schoutsen
parent 758fcc9b00
commit 381d423fec
17 changed files with 25 additions and 21 deletions

View file

@ -45,7 +45,7 @@ async def auth_manager_from_config(
) )
) )
else: else:
providers = () providers = []
# So returned auth providers are in same order as config # So returned auth providers are in same order as config
provider_hash: _ProviderDict = OrderedDict() provider_hash: _ProviderDict = OrderedDict()
for provider in providers: 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) *(auth_mfa_module_from_config(hass, config) for config in module_configs)
) )
else: else:
modules = () modules = []
# So returned auth modules are in same order as config # So returned auth modules are in same order as config
module_hash: _MfaModuleDict = OrderedDict() module_hash: _MfaModuleDict = OrderedDict()
for module in modules: for module in modules:

View file

@ -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__) _LOGGER = logging.getLogger(__name__)

View file

@ -36,7 +36,7 @@ from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
from homeassistant.helpers.typing import HomeAssistantType 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" DOMAIN = "group"

View file

@ -44,6 +44,7 @@ from homeassistant.components.cover import (
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -74,7 +75,7 @@ class CoverGroup(CoverDevice):
"""Initialize a CoverGroup entity.""" """Initialize a CoverGroup entity."""
self._name = name self._name = name
self._is_closed = False self._is_closed = False
self._cover_position = 100 self._cover_position: Optional[int] = 100
self._tilt_position = None self._tilt_position = None
self._supported_features = 0 self._supported_features = 0
self._assumed_state = True self._assumed_state = True
@ -178,7 +179,7 @@ class CoverGroup(CoverDevice):
return self._is_closed return self._is_closed
@property @property
def current_cover_position(self): def current_cover_position(self) -> Optional[int]:
"""Return current position for all covers.""" """Return current position for all covers."""
return self._cover_position return self._cover_position

View file

@ -45,6 +45,7 @@ from homeassistant.components.light import (
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -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__) _LOGGER = logging.getLogger(__name__)

View file

@ -18,7 +18,7 @@ from homeassistant.helpers.sun import (
from homeassistant.util import dt as dt_util 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__) _LOGGER = logging.getLogger(__name__)

View file

@ -21,7 +21,7 @@ from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from homeassistant.components.light import PLATFORM_SCHEMA, Light 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__) _LOGGER = logging.getLogger(__name__)

View file

@ -2,6 +2,7 @@
import asyncio import asyncio
from contextlib import suppress from contextlib import suppress
import logging import logging
from typing import Optional
from aiohttp import web, WSMsgType from aiohttp import web, WSMsgType
import async_timeout import async_timeout
@ -25,7 +26,7 @@ from .error import Disconnect
from .messages import error_message 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): class WebsocketAPIView(HomeAssistantView):
@ -47,7 +48,7 @@ class WebSocketHandler:
"""Initialize an active connection.""" """Initialize an active connection."""
self.hass = hass self.hass = hass
self.request = request self.request = request
self.wsock = None self.wsock: Optional[web.WebSocketResponse] = None
self._to_write: asyncio.Queue = asyncio.Queue(maxsize=MAX_PENDING_MSG) self._to_write: asyncio.Queue = asyncio.Queue(maxsize=MAX_PENDING_MSG)
self._handle_task = None self._handle_task = None
self._writer_task = None self._writer_task = None
@ -115,7 +116,7 @@ class WebSocketHandler:
# Py3.7+ # Py3.7+
if hasattr(asyncio, "current_task"): if hasattr(asyncio, "current_task"):
# pylint: disable=no-member # pylint: disable=no-member
self._handle_task = asyncio.current_task() # type: ignore self._handle_task = asyncio.current_task()
else: else:
self._handle_task = asyncio.Task.current_task() self._handle_task = asyncio.Task.current_task()

View file

@ -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): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):

View file

@ -20,7 +20,7 @@ from homeassistant.util import slugify
from .const import CONF_PASSIVE, DOMAIN, HOME_ZONE from .const import CONF_PASSIVE, DOMAIN, HOME_ZONE
# mypy: allow-untyped-defs # mypy: allow-untyped-defs, no-check-untyped-defs
@callback @callback

View file

@ -15,7 +15,7 @@ from homeassistant.setup import async_setup_component, async_process_deps_reqs
from homeassistant.util.decorator import Registry from homeassistant.util.decorator import Registry
from homeassistant.helpers import entity_registry from homeassistant.helpers import entity_registry
# mypy: allow-untyped-defs # mypy: allow-untyped-defs, no-check-untyped-defs
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
_UNDEF = object() _UNDEF = object()
@ -676,7 +676,7 @@ async def _old_conf_migrator(old_config):
class ConfigFlow(data_entry_flow.FlowHandler): class ConfigFlow(data_entry_flow.FlowHandler):
"""Base class for config flows with some helpers.""" """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.""" """Initialize a subclass, register if possible."""
super().__init_subclass__(**kwargs) # type: ignore super().__init_subclass__(**kwargs) # type: ignore
if domain is not None: if domain is not None:

View file

@ -3,7 +3,7 @@ from typing import Callable, Awaitable, Union
from homeassistant import config_entries from homeassistant import config_entries
from .typing import HomeAssistantType from .typing import HomeAssistantType
# mypy: allow-untyped-defs # mypy: allow-untyped-defs, no-check-untyped-defs
DiscoveryFunctionType = Callable[[], Union[Awaitable[bool], bool]] DiscoveryFunctionType = Callable[[], Union[Awaitable[bool], bool]]

View file

@ -13,6 +13,7 @@ from homeassistant.helpers.event import async_call_later
# mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any # mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any
# mypy: no-check-untyped-defs
STORAGE_DIR = ".storage" STORAGE_DIR = ".storage"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -6,7 +6,7 @@ detect_location_info and elevation are mocked by default during tests.
import asyncio import asyncio
import collections import collections
import math import math
from typing import Any, Optional, Tuple, Dict, cast from typing import Any, Optional, Tuple, Dict
import aiohttp import aiohttp
@ -159,7 +159,7 @@ def vincenty(
if miles: if miles:
s *= MILES_PER_KILOMETER # kilometers to 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]]: async def _get_ipapi(session: aiohttp.ClientSession) -> Optional[Dict[str, Any]]:

View file

@ -9,7 +9,7 @@ codecov==2.0.15
flake8-docstrings==1.5.0 flake8-docstrings==1.5.0
flake8==3.7.8 flake8==3.7.8
mock-open==1.3.1 mock-open==1.3.1
mypy==0.730 mypy==0.740
pre-commit==1.18.3 pre-commit==1.18.3
pydocstyle==4.0.1 pydocstyle==4.0.1
pylint==2.4.3 pylint==2.4.3

View file

@ -10,7 +10,7 @@ codecov==2.0.15
flake8-docstrings==1.5.0 flake8-docstrings==1.5.0
flake8==3.7.8 flake8==3.7.8
mock-open==1.3.1 mock-open==1.3.1
mypy==0.730 mypy==0.740
pre-commit==1.18.3 pre-commit==1.18.3
pydocstyle==4.0.1 pydocstyle==4.0.1
pylint==2.4.3 pylint==2.4.3