Type check homeassistant.scripts (#25464)

* Run mypy on homeassistant.scripts, disabling bunch of checks for now

* Declare async_initialize in AuthProvider

* Add some type hints

* Remove unreachable code

* Help mypy out

* Script docstring fixes
This commit is contained in:
Ville Skyttä 2019-07-24 23:18:40 +03:00 committed by Paulus Schoutsen
parent 10b120f11f
commit e8e84fb764
10 changed files with 39 additions and 14 deletions

View file

@ -5,7 +5,7 @@ import logging
import os
from collections import OrderedDict
from glob import glob
from typing import Dict, List, Sequence
from typing import Dict, List, Sequence, Any, Tuple, Callable
from unittest.mock import patch
from homeassistant import bootstrap, core
@ -14,6 +14,9 @@ from homeassistant.helpers.check_config import async_check_ha_config_file
import homeassistant.util.yaml.loader as yaml_loader
from homeassistant.exceptions import HomeAssistantError
# mypy: allow-untyped-calls, allow-untyped-defs
REQUIREMENTS = ('colorlog==4.0.2',)
_LOGGER = logging.getLogger(__name__)
@ -24,7 +27,7 @@ MOCKS = {
'load*': ("homeassistant.config.load_yaml", yaml_loader.load_yaml),
'secrets': ("homeassistant.util.yaml.loader.secret_yaml",
yaml_loader.secret_yaml),
}
} # type: Dict[str, Tuple[str, Callable]]
SILENCE = (
'homeassistant.scripts.check_config.yaml_loader.clear_secret_cache',
)
@ -49,7 +52,7 @@ def color(the_color, *args, reset=None):
def run(script_args: List) -> int:
"""Handle ensure config commandline script."""
"""Handle check config commandline script."""
parser = argparse.ArgumentParser(
description="Check Home Assistant configuration.")
parser.add_argument(
@ -81,7 +84,7 @@ def run(script_args: List) -> int:
res = check(config_dir, args.secrets)
domain_info = []
domain_info = [] # type: List[str]
if args.info:
domain_info = args.info.split(',')
@ -121,7 +124,7 @@ def run(script_args: List) -> int:
dump_dict(res['components'].get(domain, None))
if args.secrets:
flatsecret = {}
flatsecret = {} # type: Dict[str, str]
for sfn, sdict in res['secret_cache'].items():
sss = []
@ -152,9 +155,9 @@ def check(config_dir, secrets=False):
'yaml_files': OrderedDict(), # yaml_files loaded
'secrets': OrderedDict(), # secret cache and secrets loaded
'except': OrderedDict(), # exceptions raised (with config)
'components': None, # successful components
#'components' is a HomeAssistantConfig # noqa: E265
'secret_cache': None,
}
} # type: Dict[str, Any]
# pylint: disable=possibly-unused-variable
def mock_load(filename):