From e86919a99747349e6ea919665fce82766e6fffcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 14 Mar 2020 12:39:28 +0200 Subject: [PATCH] Type hint improvements (#32793) --- homeassistant/bootstrap.py | 3 ++- homeassistant/loader.py | 4 ++-- homeassistant/setup.py | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 7d4155257db..000c23e1d96 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -20,6 +20,7 @@ from homeassistant.const import ( REQUIRED_NEXT_PYTHON_VER, ) from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.typing import ConfigType from homeassistant.setup import DATA_SETUP, async_setup_component from homeassistant.util.logging import AsyncHandler from homeassistant.util.package import async_get_user_site, is_virtual_env @@ -133,7 +134,7 @@ async def async_setup_hass( async def async_from_config_dict( - config: Dict[str, Any], hass: core.HomeAssistant + config: ConfigType, hass: core.HomeAssistant ) -> Optional[core.HomeAssistant]: """Try to configure Home Assistant from a configuration dictionary. diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 155dd0e059d..b2e1fa74fba 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -74,7 +74,7 @@ async def _async_get_custom_components( except ImportError: return {} - def get_sub_directories(paths: List) -> List: + def get_sub_directories(paths: List[str]) -> List[pathlib.Path]: """Return all sub directories in a set of paths.""" return [ entry @@ -506,7 +506,7 @@ async def async_component_dependencies(hass: "HomeAssistant", domain: str) -> Se async def _async_component_dependencies( - hass: "HomeAssistant", domain: str, loaded: Set[str], loading: Set + hass: "HomeAssistant", domain: str, loaded: Set[str], loading: Set[str] ) -> Set[str]: """Recursive function to get component dependencies. diff --git a/homeassistant/setup.py b/homeassistant/setup.py index f62228b28f5..40d767728d3 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -3,12 +3,13 @@ import asyncio import logging.handlers from timeit import default_timer as timer from types import ModuleType -from typing import Awaitable, Callable, Dict, List, Optional +from typing import Awaitable, Callable, List, Optional from homeassistant import config as conf_util, core, loader, requirements from homeassistant.config import async_notify_setup_error from homeassistant.const import EVENT_COMPONENT_LOADED, PLATFORM_FORMAT from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -20,7 +21,7 @@ DATA_DEPS_REQS = "deps_reqs_processed" SLOW_SETUP_WARNING = 10 -def setup_component(hass: core.HomeAssistant, domain: str, config: Dict) -> bool: +def setup_component(hass: core.HomeAssistant, domain: str, config: ConfigType) -> bool: """Set up a component and all its dependencies.""" return asyncio.run_coroutine_threadsafe( async_setup_component(hass, domain, config), hass.loop @@ -28,7 +29,7 @@ def setup_component(hass: core.HomeAssistant, domain: str, config: Dict) -> bool async def async_setup_component( - hass: core.HomeAssistant, domain: str, config: Dict + hass: core.HomeAssistant, domain: str, config: ConfigType ) -> bool: """Set up a component and all its dependencies. @@ -50,7 +51,7 @@ async def async_setup_component( async def _async_process_dependencies( - hass: core.HomeAssistant, config: Dict, name: str, dependencies: List[str] + hass: core.HomeAssistant, config: ConfigType, name: str, dependencies: List[str] ) -> bool: """Ensure all dependencies are set up.""" blacklisted = [dep for dep in dependencies if dep in loader.DEPENDENCY_BLACKLIST] @@ -85,7 +86,7 @@ async def _async_process_dependencies( async def _async_setup_component( - hass: core.HomeAssistant, domain: str, config: Dict + hass: core.HomeAssistant, domain: str, config: ConfigType ) -> bool: """Set up a component for Home Assistant. @@ -212,7 +213,7 @@ async def _async_setup_component( async def async_prepare_setup_platform( - hass: core.HomeAssistant, hass_config: Dict, domain: str, platform_name: str + hass: core.HomeAssistant, hass_config: ConfigType, domain: str, platform_name: str ) -> Optional[ModuleType]: """Load a platform and makes sure dependencies are setup. @@ -267,7 +268,7 @@ async def async_prepare_setup_platform( async def async_process_deps_reqs( - hass: core.HomeAssistant, config: Dict, integration: loader.Integration + hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration ) -> None: """Process all dependencies and requirements for a module.