Type hint improvements (#32793)

This commit is contained in:
Ville Skyttä 2020-03-14 12:39:28 +02:00 committed by GitHub
parent d04479044c
commit e86919a997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -20,6 +20,7 @@ from homeassistant.const import (
REQUIRED_NEXT_PYTHON_VER, REQUIRED_NEXT_PYTHON_VER,
) )
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import DATA_SETUP, async_setup_component from homeassistant.setup import DATA_SETUP, async_setup_component
from homeassistant.util.logging import AsyncHandler from homeassistant.util.logging import AsyncHandler
from homeassistant.util.package import async_get_user_site, is_virtual_env 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( async def async_from_config_dict(
config: Dict[str, Any], hass: core.HomeAssistant config: ConfigType, hass: core.HomeAssistant
) -> Optional[core.HomeAssistant]: ) -> Optional[core.HomeAssistant]:
"""Try to configure Home Assistant from a configuration dictionary. """Try to configure Home Assistant from a configuration dictionary.

View File

@ -74,7 +74,7 @@ async def _async_get_custom_components(
except ImportError: except ImportError:
return {} 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 all sub directories in a set of paths."""
return [ return [
entry entry
@ -506,7 +506,7 @@ async def async_component_dependencies(hass: "HomeAssistant", domain: str) -> Se
async def _async_component_dependencies( 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]: ) -> Set[str]:
"""Recursive function to get component dependencies. """Recursive function to get component dependencies.

View File

@ -3,12 +3,13 @@ import asyncio
import logging.handlers import logging.handlers
from timeit import default_timer as timer from timeit import default_timer as timer
from types import ModuleType 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 import config as conf_util, core, loader, requirements
from homeassistant.config import async_notify_setup_error from homeassistant.config import async_notify_setup_error
from homeassistant.const import EVENT_COMPONENT_LOADED, PLATFORM_FORMAT from homeassistant.const import EVENT_COMPONENT_LOADED, PLATFORM_FORMAT
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -20,7 +21,7 @@ DATA_DEPS_REQS = "deps_reqs_processed"
SLOW_SETUP_WARNING = 10 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.""" """Set up a component and all its dependencies."""
return asyncio.run_coroutine_threadsafe( return asyncio.run_coroutine_threadsafe(
async_setup_component(hass, domain, config), hass.loop 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( async def async_setup_component(
hass: core.HomeAssistant, domain: str, config: Dict hass: core.HomeAssistant, domain: str, config: ConfigType
) -> bool: ) -> bool:
"""Set up a component and all its dependencies. """Set up a component and all its dependencies.
@ -50,7 +51,7 @@ async def async_setup_component(
async def _async_process_dependencies( 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: ) -> bool:
"""Ensure all dependencies are set up.""" """Ensure all dependencies are set up."""
blacklisted = [dep for dep in dependencies if dep in loader.DEPENDENCY_BLACKLIST] 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( async def _async_setup_component(
hass: core.HomeAssistant, domain: str, config: Dict hass: core.HomeAssistant, domain: str, config: ConfigType
) -> bool: ) -> bool:
"""Set up a component for Home Assistant. """Set up a component for Home Assistant.
@ -212,7 +213,7 @@ async def _async_setup_component(
async def async_prepare_setup_platform( 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]: ) -> Optional[ModuleType]:
"""Load a platform and makes sure dependencies are setup. """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( async def async_process_deps_reqs(
hass: core.HomeAssistant, config: Dict, integration: loader.Integration hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration
) -> None: ) -> None:
"""Process all dependencies and requirements for a module. """Process all dependencies and requirements for a module.