Add typing to homeassistant/*.py and homeassistant/util/ (#15569)
* Add typing to homeassistant/*.py and homeassistant/util/ * Fix wrong merge * Restore iterable in OrderedSet * Fix tests
This commit is contained in:
1 parent
b7c336a687
commit
140a874917
27 files changed
+532
-384
No files matched your search
+13
-9
@@ -4,7 +4,7 @@ import logging.handlers
|
||||
from timeit import default_timer as timer
|
||||
|
||||
from types import ModuleType
|
||||
from typing import Optional, Dict
|
||||
from typing import Optional, Dict, List
|
||||
|
||||
from homeassistant import requirements, core, loader, config as conf_util
|
||||
from homeassistant.config import async_notify_setup_error
|
||||
@@ -56,7 +56,9 @@ async def async_setup_component(hass: core.HomeAssistant, domain: str,
|
||||
return await task # type: ignore
|
||||
|
||||
|
||||
async def _async_process_dependencies(hass, config, name, dependencies):
|
||||
async def _async_process_dependencies(
|
||||
hass: core.HomeAssistant, config: Dict, name: str,
|
||||
dependencies: List[str]) -> bool:
|
||||
"""Ensure all dependencies are set up."""
|
||||
blacklisted = [dep for dep in dependencies
|
||||
if dep in loader.DEPENDENCY_BLACKLIST]
|
||||
@@ -88,12 +90,12 @@ async def _async_process_dependencies(hass, config, name, dependencies):
|
||||
|
||||
|
||||
async def _async_setup_component(hass: core.HomeAssistant,
|
||||
domain: str, config) -> bool:
|
||||
domain: str, config: Dict) -> bool:
|
||||
"""Set up a component for Home Assistant.
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
def log_error(msg, link=True):
|
||||
def log_error(msg: str, link: bool = True) -> None:
|
||||
"""Log helper."""
|
||||
_LOGGER.error("Setup failed for %s: %s", domain, msg)
|
||||
async_notify_setup_error(hass, domain, link)
|
||||
@@ -181,7 +183,7 @@ async def _async_setup_component(hass: core.HomeAssistant,
|
||||
return True
|
||||
|
||||
|
||||
async def async_prepare_setup_platform(hass: core.HomeAssistant, config,
|
||||
async def async_prepare_setup_platform(hass: core.HomeAssistant, config: Dict,
|
||||
domain: str, platform_name: str) \
|
||||
-> Optional[ModuleType]:
|
||||
"""Load a platform and makes sure dependencies are setup.
|
||||
@@ -190,7 +192,7 @@ async def async_prepare_setup_platform(hass: core.HomeAssistant, config,
|
||||
"""
|
||||
platform_path = PLATFORM_FORMAT.format(domain, platform_name)
|
||||
|
||||
def log_error(msg):
|
||||
def log_error(msg: str) -> None:
|
||||
"""Log helper."""
|
||||
_LOGGER.error("Unable to prepare setup for platform %s: %s",
|
||||
platform_path, msg)
|
||||
@@ -217,7 +219,9 @@ async def async_prepare_setup_platform(hass: core.HomeAssistant, config,
|
||||
return platform
|
||||
|
||||
|
||||
async def async_process_deps_reqs(hass, config, name, module):
|
||||
async def async_process_deps_reqs(
|
||||
hass: core.HomeAssistant, config: Dict, name: str,
|
||||
module: ModuleType) -> None:
|
||||
"""Process all dependencies and requirements for a module.
|
||||
|
||||
Module is a Python module of either a component or platform.
|
||||
@@ -231,14 +235,14 @@ async def async_process_deps_reqs(hass, config, name, module):
|
||||
|
||||
if hasattr(module, 'DEPENDENCIES'):
|
||||
dep_success = await _async_process_dependencies(
|
||||
hass, config, name, module.DEPENDENCIES)
|
||||
hass, config, name, module.DEPENDENCIES) # type: ignore
|
||||
|
||||
if not dep_success:
|
||||
raise HomeAssistantError("Could not setup all dependencies.")
|
||||
|
||||
if not hass.config.skip_pip and hasattr(module, 'REQUIREMENTS'):
|
||||
req_success = await requirements.async_process_requirements(
|
||||
hass, name, module.REQUIREMENTS)
|
||||
hass, name, module.REQUIREMENTS) # type: ignore
|
||||
|
||||
if not req_success:
|
||||
raise HomeAssistantError("Could not install all requirements.")
|
||||
|
||||
Reference in new issue
Block a user