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 asyncio
import logging import logging
from collections import OrderedDict from collections import OrderedDict
from typing import List, Awaitable
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.core import callback from homeassistant.core import callback, HomeAssistant
from . import models from . import models
from . import auth_store from . import auth_store
@ -13,7 +14,9 @@ from .providers import auth_provider_from_config
_LOGGER = logging.getLogger(__name__) _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.""" """Initialize an auth manager from config."""
store = auth_store.AuthStore(hass) store = auth_store.AuthStore(hass)
if provider_configs: if provider_configs:

View File

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

View File

@ -6,10 +6,11 @@ https://home-assistant.io/components/persistent_notification/
""" """
import asyncio import asyncio
import logging import logging
from typing import Awaitable
import voluptuous as vol import voluptuous as vol
from homeassistant.core import callback from homeassistant.core import callback, HomeAssistant
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
@ -58,7 +59,8 @@ def dismiss(hass, notification_id):
@callback @callback
@bind_hass @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.""" """Generate a notification."""
data = { data = {
key: value for key, value in [ 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 ] 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 @callback
@ -81,7 +84,7 @@ def async_dismiss(hass, notification_id):
@asyncio.coroutine @asyncio.coroutine
def async_setup(hass, config): def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]:
"""Set up the persistent notification component.""" """Set up the persistent notification component."""
@callback @callback
def create_service(call): def create_service(call):

View File

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

View File

@ -2,6 +2,7 @@
from collections import OrderedDict from collections import OrderedDict
import fnmatch import fnmatch
import re import re
from typing import Dict
from homeassistant.core import split_entity_id from homeassistant.core import split_entity_id
@ -9,7 +10,8 @@ from homeassistant.core import split_entity_id
class EntityValues: class EntityValues:
"""Class to store entity id based values.""" """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.""" """Initialize an EntityConfigDict."""
self._cache = {} self._cache = {}
self._exact = exact self._exact = exact

View File

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

View File

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