diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 00c2a684c0b..b98dc07deb6 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -3,8 +3,9 @@ from __future__ import annotations import asyncio from collections import OrderedDict +from collections.abc import Mapping from datetime import timedelta -from typing import Any, Mapping, Optional, cast +from typing import Any, Optional, cast import jwt diff --git a/homeassistant/auth/permissions/types.py b/homeassistant/auth/permissions/types.py index 6ce394ebb92..e335ba9f989 100644 --- a/homeassistant/auth/permissions/types.py +++ b/homeassistant/auth/permissions/types.py @@ -1,5 +1,6 @@ """Common code for permissions.""" -from typing import Mapping, Union +from collections.abc import Mapping +from typing import Union # MyPy doesn't support recursion yet. So writing it out as far as we need. diff --git a/homeassistant/auth/permissions/util.py b/homeassistant/auth/permissions/util.py index 175da4d4a0c..60e68e8b7ca 100644 --- a/homeassistant/auth/permissions/util.py +++ b/homeassistant/auth/permissions/util.py @@ -1,8 +1,9 @@ """Helpers to deal with permissions.""" from __future__ import annotations +from collections.abc import Callable from functools import wraps -from typing import Callable, Optional, cast +from typing import Optional, cast from .const import SUBCAT_ALL from .models import PermissionLookup diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index d10315afa85..dd73589b573 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -2,14 +2,14 @@ from __future__ import annotations import asyncio -from collections.abc import Iterable, Mapping +from collections.abc import Callable, Iterable, Mapping from contextvars import ContextVar import dataclasses from enum import Enum import functools import logging from types import MappingProxyType, MethodType -from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, cast +from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast import weakref from . import data_entry_flow, loader diff --git a/homeassistant/core.py b/homeassistant/core.py index 3b0bac63815..30e98da7637 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -7,7 +7,14 @@ of entities and react to changes. from __future__ import annotations import asyncio -from collections.abc import Collection, Coroutine, Iterable, Mapping +from collections.abc import ( + Awaitable, + Callable, + Collection, + Coroutine, + Iterable, + Mapping, +) import datetime import enum import functools @@ -21,8 +28,6 @@ from types import MappingProxyType from typing import ( TYPE_CHECKING, Any, - Awaitable, - Callable, Generic, NamedTuple, Optional, diff --git a/homeassistant/helpers/collection.py b/homeassistant/helpers/collection.py index 57e34a02d96..f6f9c968f10 100644 --- a/homeassistant/helpers/collection.py +++ b/homeassistant/helpers/collection.py @@ -3,11 +3,11 @@ from __future__ import annotations from abc import ABC, abstractmethod import asyncio -from collections.abc import Coroutine +from collections.abc import Awaitable, Callable, Coroutine, Iterable from dataclasses import dataclass from itertools import groupby import logging -from typing import Any, Awaitable, Callable, Iterable, Optional, cast +from typing import Any, Optional, cast import voluptuous as vol from voluptuous.humanize import humanize_error diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index d1ece8a85df..80bed9137d0 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -3,14 +3,14 @@ from __future__ import annotations import asyncio from collections import deque -from collections.abc import Container, Generator +from collections.abc import Callable, Container, Generator from contextlib import contextmanager from datetime import datetime, time as dt_time, timedelta import functools as ft import logging import re import sys -from typing import Any, Callable, cast +from typing import Any, cast from homeassistant.components import zone as zone_cmp from homeassistant.components.device_automation import ( diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 73125b707ec..6f07e5d665e 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -1,9 +1,9 @@ """Helpers for data entry flows for config entries.""" from __future__ import annotations -import asyncio # pylint: disable=unused-import # used in cast as string +from collections.abc import Awaitable, Callable import logging -from typing import Any, Awaitable, Callable, Union, cast +from typing import TYPE_CHECKING, Any, Union, cast from homeassistant import config_entries from homeassistant.components import dhcp, mqtt, ssdp, zeroconf @@ -12,6 +12,9 @@ from homeassistant.data_entry_flow import FlowResult from .typing import UNDEFINED, DiscoveryInfoType, UndefinedType +if TYPE_CHECKING: + import asyncio + DiscoveryFunctionType = Callable[[HomeAssistant], Union[Awaitable[bool], bool]] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index d29c519de36..14b45a52ecd 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -2,14 +2,14 @@ from __future__ import annotations import asyncio -from collections.abc import Awaitable, Iterable, Sequence +from collections.abc import Awaitable, Callable, Iterable, Sequence import copy from dataclasses import dataclass from datetime import datetime, timedelta import functools as ft import logging import time -from typing import Any, Callable, Union, cast +from typing import Any, Union, cast import attr from typing_extensions import Concatenate, ParamSpec diff --git a/homeassistant/helpers/significant_change.py b/homeassistant/helpers/significant_change.py index d2791def987..c1dbaf8c6e4 100644 --- a/homeassistant/helpers/significant_change.py +++ b/homeassistant/helpers/significant_change.py @@ -28,8 +28,9 @@ The following cases will never be passed to your function: """ from __future__ import annotations +from collections.abc import Callable from types import MappingProxyType -from typing import Any, Callable, Optional, Union +from typing import Any, Optional, Union from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.core import HomeAssistant, State, callback diff --git a/homeassistant/helpers/singleton.py b/homeassistant/helpers/singleton.py index a3cde0b2f27..7012241fe4e 100644 --- a/homeassistant/helpers/singleton.py +++ b/homeassistant/helpers/singleton.py @@ -2,8 +2,9 @@ from __future__ import annotations import asyncio +from collections.abc import Callable import functools -from typing import Callable, TypeVar, cast +from typing import TypeVar, cast from homeassistant.core import HomeAssistant from homeassistant.loader import bind_hass diff --git a/homeassistant/helpers/typing.py b/homeassistant/helpers/typing.py index e04e29f8c24..a7430d1fe69 100644 --- a/homeassistant/helpers/typing.py +++ b/homeassistant/helpers/typing.py @@ -1,6 +1,7 @@ """Typing Helpers for Home Assistant.""" +from collections.abc import Mapping from enum import Enum -from typing import Any, Mapping, Optional, Union +from typing import Any, Optional, Union import homeassistant.core diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 05000032796..da23d1141bd 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -7,6 +7,7 @@ documentation as possible to keep it understandable. from __future__ import annotations import asyncio +from collections.abc import Callable from contextlib import suppress import functools as ft import importlib @@ -15,7 +16,7 @@ import logging import pathlib import sys from types import ModuleType -from typing import TYPE_CHECKING, Any, Callable, TypedDict, TypeVar, cast +from typing import TYPE_CHECKING, Any, TypedDict, TypeVar, cast from awesomeversion import ( AwesomeVersion, diff --git a/homeassistant/util/logging.py b/homeassistant/util/logging.py index dd3cb119c6b..9216993eb53 100644 --- a/homeassistant/util/logging.py +++ b/homeassistant/util/logging.py @@ -2,14 +2,14 @@ from __future__ import annotations import asyncio -from collections.abc import Coroutine +from collections.abc import Awaitable, Callable, Coroutine from functools import partial, wraps import inspect import logging import logging.handlers import queue import traceback -from typing import Any, Awaitable, Callable, cast, overload +from typing import Any, cast, overload from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE from homeassistant.core import HomeAssistant, callback, is_callback @@ -106,7 +106,7 @@ def log_exception(format_err: Callable[..., Any], *args: Any) -> None: @overload -def catch_log_exception( # type: ignore +def catch_log_exception( # type: ignore[misc] func: Callable[..., Awaitable[Any]], format_err: Callable[..., Any], *args: Any ) -> Callable[..., Awaitable[None]]: """Overload for Callables that return an Awaitable."""