Update typing 03 (#48015)

This commit is contained in:
Marc Mueller
2021-03-17 21:46:07 +01:00
committed by GitHub
parent 6fb2e63e49
commit fabd73f08b
37 changed files with 417 additions and 379 deletions

View File

@@ -1,11 +1,13 @@
"""Home Assistant command line scripts."""
from __future__ import annotations
import argparse
import asyncio
import importlib
import logging
import os
import sys
from typing import List, Optional, Sequence, Text
from typing import Sequence
from homeassistant import runner
from homeassistant.bootstrap import async_mount_local_lib_path
@@ -16,7 +18,7 @@ from homeassistant.util.package import install_package, is_installed, is_virtual
# mypy: allow-untyped-defs, no-warn-return-any
def run(args: List) -> int:
def run(args: list) -> int:
"""Run a script."""
scripts = []
path = os.path.dirname(__file__)
@@ -65,7 +67,7 @@ def run(args: List) -> int:
return script.run(args[1:]) # type: ignore
def extract_config_dir(args: Optional[Sequence[Text]] = None) -> str:
def extract_config_dir(args: Sequence[str] | None = None) -> str:
"""Extract the config dir from the arguments or get the default."""
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-c", "--config", default=None)

View File

@@ -1,4 +1,6 @@
"""Script to run benchmarks."""
from __future__ import annotations
import argparse
import asyncio
import collections
@@ -7,7 +9,7 @@ from datetime import datetime
import json
import logging
from timeit import default_timer as timer
from typing import Callable, Dict, TypeVar
from typing import Callable, TypeVar
from homeassistant import core
from homeassistant.components.websocket_api.const import JSON_DUMP
@@ -21,7 +23,7 @@ from homeassistant.util import dt as dt_util
CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable) # pylint: disable=invalid-name
BENCHMARKS: Dict[str, Callable] = {}
BENCHMARKS: dict[str, Callable] = {}
def run(args):

View File

@@ -1,4 +1,6 @@
"""Script to check the configuration file."""
from __future__ import annotations
import argparse
import asyncio
from collections import OrderedDict
@@ -6,7 +8,7 @@ from collections.abc import Mapping, Sequence
from glob import glob
import logging
import os
from typing import Any, Callable, Dict, List, Tuple
from typing import Any, Callable
from unittest.mock import patch
from homeassistant import core
@@ -22,13 +24,13 @@ REQUIREMENTS = ("colorlog==4.7.2",)
_LOGGER = logging.getLogger(__name__)
# pylint: disable=protected-access
MOCKS: Dict[str, Tuple[str, Callable]] = {
MOCKS: dict[str, tuple[str, Callable]] = {
"load": ("homeassistant.util.yaml.loader.load_yaml", yaml_loader.load_yaml),
"load*": ("homeassistant.config.load_yaml", yaml_loader.load_yaml),
"secrets": ("homeassistant.util.yaml.loader.secret_yaml", yaml_loader.secret_yaml),
}
PATCHES: Dict[str, Any] = {}
PATCHES: dict[str, Any] = {}
C_HEAD = "bold"
ERROR_STR = "General Errors"
@@ -48,7 +50,7 @@ def color(the_color, *args, reset=None):
raise ValueError(f"Invalid color {k!s} in {the_color}") from k
def run(script_args: List) -> int:
def run(script_args: list) -> int:
"""Handle check config commandline script."""
parser = argparse.ArgumentParser(description="Check Home Assistant configuration.")
parser.add_argument("--script", choices=["check_config"])
@@ -83,7 +85,7 @@ def run(script_args: List) -> int:
res = check(config_dir, args.secrets)
domain_info: List[str] = []
domain_info: list[str] = []
if args.info:
domain_info = args.info.split(",")
@@ -123,7 +125,7 @@ def run(script_args: List) -> int:
dump_dict(res["components"].get(domain))
if args.secrets:
flatsecret: Dict[str, str] = {}
flatsecret: dict[str, str] = {}
for sfn, sdict in res["secret_cache"].items():
sss = []
@@ -149,7 +151,7 @@ def run(script_args: List) -> int:
def check(config_dir, secrets=False):
"""Perform a check by mocking hass load functions."""
logging.getLogger("homeassistant.loader").setLevel(logging.CRITICAL)
res: Dict[str, Any] = {
res: dict[str, Any] = {
"yaml_files": OrderedDict(), # yaml_files loaded
"secrets": OrderedDict(), # secret cache and secrets loaded
"except": OrderedDict(), # exceptions raised (with config)