Add disallow_untyped_calls to mypy check. (#15661)

* Add disallow_untyped_calls to mypy check.

* Fix generator
This commit is contained in:
Andrey 2018-07-31 17:00:17 +03:00 committed by Paulus Schoutsen
parent 951372491c
commit 8ee3b535ef
7 changed files with 29 additions and 18 deletions

View file

@ -2,9 +2,10 @@
import asyncio
import logging
from collections import OrderedDict
from typing import List, Awaitable
from homeassistant import data_entry_flow
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from . import models
from . import auth_store
@ -13,7 +14,9 @@ from .providers import auth_provider_from_config
_LOGGER = logging.getLogger(__name__)
async def auth_manager_from_config(hass, provider_configs):
async def auth_manager_from_config(
hass: HomeAssistant,
provider_configs: List[dict]) -> Awaitable['AuthManager']:
"""Initialize an auth manager from config."""
store = auth_store.AuthStore(hass)
if provider_configs:

View file

@ -10,6 +10,7 @@ Component design guidelines:
import asyncio
import itertools as it
import logging
from typing import Awaitable
import homeassistant.core as ha
import homeassistant.config as conf_util
@ -109,7 +110,7 @@ def async_reload_core_config(hass):
@asyncio.coroutine
def async_setup(hass, config):
def async_setup(hass: ha.HomeAssistant, config: dict) -> Awaitable[bool]:
"""Set up general services related to Home Assistant."""
@asyncio.coroutine
def async_handle_turn_service(service):

View file

@ -6,10 +6,11 @@ https://home-assistant.io/components/persistent_notification/
"""
import asyncio
import logging
from typing import Awaitable
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.exceptions import TemplateError
from homeassistant.loader import bind_hass
from homeassistant.helpers import config_validation as cv
@ -58,7 +59,8 @@ def dismiss(hass, notification_id):
@callback
@bind_hass
def async_create(hass, message, title=None, notification_id=None):
def async_create(hass: HomeAssistant, message: str, title: str = None,
notification_id: str = None) -> None:
"""Generate a notification."""
data = {
key: value for key, value in [
@ -68,7 +70,8 @@ def async_create(hass, message, title=None, notification_id=None):
] if value is not None
}
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_CREATE, data))
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_CREATE, data))
@callback
@ -81,7 +84,7 @@ def async_dismiss(hass, notification_id):
@asyncio.coroutine
def async_setup(hass, config):
def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]:
"""Set up the persistent notification component."""
@callback
def create_service(call):

View file

@ -113,7 +113,7 @@ the flow from the config panel.
import logging
import uuid
from typing import Set, Optional # noqa pylint: disable=unused-import
from typing import Set, Optional, List # noqa pylint: disable=unused-import
from homeassistant import data_entry_flow
from homeassistant.core import callback, HomeAssistant
@ -270,19 +270,19 @@ class ConfigEntries:
An instance of this object is available via `hass.config_entries`.
"""
def __init__(self, hass, hass_config):
def __init__(self, hass: HomeAssistant, hass_config: dict) -> None:
"""Initialize the entry manager."""
self.hass = hass
self.flow = data_entry_flow.FlowManager(
hass, self._async_create_flow, self._async_finish_flow)
self._hass_config = hass_config
self._entries = None
self._entries = [] # type: List[ConfigEntry]
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
@callback
def async_domains(self):
def async_domains(self) -> List[str]:
"""Return domains for which we have entries."""
seen = set() # type: Set[ConfigEntry]
seen = set() # type: Set[str]
result = []
for entry in self._entries:
@ -293,7 +293,7 @@ class ConfigEntries:
return result
@callback
def async_entries(self, domain=None):
def async_entries(self, domain: str = None) -> List[ConfigEntry]:
"""Return all entries or entries for a specific domain."""
if domain is None:
return list(self._entries)
@ -319,7 +319,7 @@ class ConfigEntries:
'require_restart': not unloaded
}
async def async_load(self):
async def async_load(self) -> None:
"""Handle loading the config."""
# Migrating for config entries stored before 0.73
config = await self.hass.helpers.storage.async_migrator(

View file

@ -2,6 +2,7 @@
from collections import OrderedDict
import fnmatch
import re
from typing import Dict
from homeassistant.core import split_entity_id
@ -9,7 +10,8 @@ from homeassistant.core import split_entity_id
class EntityValues:
"""Class to store entity id based values."""
def __init__(self, exact=None, domain=None, glob=None):
def __init__(self, exact: Dict = None, domain: Dict = None,
glob: Dict = None) -> None:
"""Initialize an EntityConfigDict."""
self._cache = {}
self._exact = exact

View file

@ -3,7 +3,7 @@ import logging
import signal
import sys
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.const import RESTART_EXIT_CODE
from homeassistant.loader import bind_hass
@ -12,13 +12,13 @@ _LOGGER = logging.getLogger(__name__)
@callback
@bind_hass
def async_register_signal_handling(hass):
def async_register_signal_handling(hass: HomeAssistant) -> None:
"""Register system signal handler for core."""
if sys.platform != 'win32':
@callback
def async_signal_handle(exit_code):
"""Wrap signal handling."""
hass.async_add_job(hass.async_stop(exit_code))
hass.async_create_task(hass.async_stop(exit_code))
try:
hass.loop.add_signal_handler(

View file

@ -1,5 +1,6 @@
[mypy]
check_untyped_defs = true
disallow_untyped_calls = true
follow_imports = silent
ignore_missing_imports = true
warn_incomplete_stub = true
@ -16,4 +17,5 @@ disallow_untyped_defs = false
[mypy-homeassistant.util.yaml]
warn_return_any = false
disallow_untyped_calls = false