Update Union typing (4) [Py310] (#86427)
This commit is contained in:
parent
b0ed0d5d41
commit
8abce25948
11 changed files with 39 additions and 37 deletions
|
@ -1,29 +1,28 @@
|
||||||
"""Common code for permissions."""
|
"""Common code for permissions."""
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
# MyPy doesn't support recursion yet. So writing it out as far as we need.
|
# MyPy doesn't support recursion yet. So writing it out as far as we need.
|
||||||
|
|
||||||
ValueType = Union[
|
ValueType = (
|
||||||
# Example: entities.all = { read: true, control: true }
|
# Example: entities.all = { read: true, control: true }
|
||||||
Mapping[str, bool],
|
Mapping[str, bool]
|
||||||
bool,
|
| bool
|
||||||
None,
|
| None
|
||||||
]
|
)
|
||||||
|
|
||||||
# Example: entities.domains = { light: … }
|
# Example: entities.domains = { light: … }
|
||||||
SubCategoryDict = Mapping[str, ValueType]
|
SubCategoryDict = Mapping[str, ValueType]
|
||||||
|
|
||||||
SubCategoryType = Union[SubCategoryDict, bool, None]
|
SubCategoryType = SubCategoryDict | bool | None
|
||||||
|
|
||||||
CategoryType = Union[
|
CategoryType = (
|
||||||
# Example: entities.domains
|
# Example: entities.domains
|
||||||
Mapping[str, SubCategoryType],
|
Mapping[str, SubCategoryType]
|
||||||
# Example: entities.all
|
# Example: entities.all
|
||||||
Mapping[str, ValueType],
|
| Mapping[str, ValueType]
|
||||||
bool,
|
| bool
|
||||||
None,
|
| None
|
||||||
]
|
)
|
||||||
|
|
||||||
# Example: { entities: … }
|
# Example: { entities: … }
|
||||||
PolicyType = Mapping[str, CategoryType]
|
PolicyType = Mapping[str, CategoryType]
|
||||||
|
|
|
@ -14,7 +14,7 @@ from ipaddress import (
|
||||||
ip_address,
|
ip_address,
|
||||||
ip_network,
|
ip_network,
|
||||||
)
|
)
|
||||||
from typing import Any, Union, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow
|
||||||
from .. import InvalidAuthError
|
from .. import InvalidAuthError
|
||||||
from ..models import Credentials, RefreshToken, UserMeta
|
from ..models import Credentials, RefreshToken, UserMeta
|
||||||
|
|
||||||
IPAddress = Union[IPv4Address, IPv6Address]
|
IPAddress = IPv4Address | IPv6Address
|
||||||
IPNetwork = Union[IPv4Network, IPv6Network]
|
IPNetwork = IPv4Network | IPv6Network
|
||||||
|
|
||||||
CONF_TRUSTED_NETWORKS = "trusted_networks"
|
CONF_TRUSTED_NETWORKS = "trusted_networks"
|
||||||
CONF_TRUSTED_USERS = "trusted_users"
|
CONF_TRUSTED_USERS = "trusted_users"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from typing import Final, Union, cast
|
from typing import Final, cast
|
||||||
|
|
||||||
from homeassistant.components.stream import Orientation
|
from homeassistant.components.stream import Orientation
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -33,7 +33,7 @@ class CameraPreferences:
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
# The orientation prefs are stored in in the entity registry options
|
# The orientation prefs are stored in in the entity registry options
|
||||||
# The preload_stream prefs are stored in this Store
|
# The preload_stream prefs are stored in this Store
|
||||||
self._store = Store[dict[str, dict[str, Union[bool, Orientation]]]](
|
self._store = Store[dict[str, dict[str, bool | Orientation]]](
|
||||||
hass, STORAGE_VERSION, STORAGE_KEY
|
hass, STORAGE_VERSION, STORAGE_KEY
|
||||||
)
|
)
|
||||||
self._dynamic_stream_settings_by_entity_id: dict[
|
self._dynamic_stream_settings_by_entity_id: dict[
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
from typing import Literal, TypedDict, Union
|
from typing import Literal, TypedDict
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -120,9 +120,13 @@ class WaterSourceType(TypedDict):
|
||||||
number_energy_price: float | None # Price for energy ($/m³)
|
number_energy_price: float | None # Price for energy ($/m³)
|
||||||
|
|
||||||
|
|
||||||
SourceType = Union[
|
SourceType = (
|
||||||
GridSourceType, SolarSourceType, BatterySourceType, GasSourceType, WaterSourceType
|
GridSourceType
|
||||||
]
|
| SolarSourceType
|
||||||
|
| BatterySourceType
|
||||||
|
| GasSourceType
|
||||||
|
| WaterSourceType
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DeviceConsumption(TypedDict):
|
class DeviceConsumption(TypedDict):
|
||||||
|
|
|
@ -7,7 +7,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from typing import Any, Final, TypedDict, Union, cast
|
from typing import Any, Final, TypedDict, cast
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiohttp.typedefs import StrOrURL
|
from aiohttp.typedefs import StrOrURL
|
||||||
|
@ -498,7 +498,7 @@ async def start_http_server_and_save_config(
|
||||||
|
|
||||||
if CONF_TRUSTED_PROXIES in conf:
|
if CONF_TRUSTED_PROXIES in conf:
|
||||||
conf[CONF_TRUSTED_PROXIES] = [
|
conf[CONF_TRUSTED_PROXIES] = [
|
||||||
str(cast(Union[IPv4Network, IPv6Network], ip).network_address)
|
str(cast(IPv4Network | IPv6Network, ip).network_address)
|
||||||
for ip in conf[CONF_TRUSTED_PROXIES]
|
for ip in conf[CONF_TRUSTED_PROXIES]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from collections.abc import Callable, Coroutine
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypedDict, Union
|
from typing import TYPE_CHECKING, Any, TypedDict
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_THIS = "this"
|
ATTR_THIS = "this"
|
||||||
|
|
||||||
PublishPayloadType = Union[str, bytes, int, float, None]
|
PublishPayloadType = str | bytes | int | float | None
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True, frozen=True)
|
@attr.s(slots=True, frozen=True)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union, cast
|
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import onboarding
|
from homeassistant.components import onboarding
|
||||||
|
@ -176,7 +176,7 @@ def register_discovery_flow(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Register flow for discovered integrations that not require auth."""
|
"""Register flow for discovered integrations that not require auth."""
|
||||||
|
|
||||||
class DiscoveryFlow(DiscoveryFlowHandler[Union[Awaitable[bool], bool]]):
|
class DiscoveryFlow(DiscoveryFlowHandler[Awaitable[bool] | bool]):
|
||||||
"""Discovery flow handler."""
|
"""Discovery flow handler."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
|
@ -11,7 +11,7 @@ from functools import partial
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any, TypedDict, Union, cast
|
from typing import Any, TypedDict, cast
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -1110,7 +1110,7 @@ async def _async_stop_scripts_at_shutdown(hass, event):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_VarsType = Union[dict[str, Any], MappingProxyType]
|
_VarsType = dict[str, Any] | MappingProxyType
|
||||||
|
|
||||||
|
|
||||||
def _referenced_extract_ids(data: Any, key: str, found: set[str]) -> None:
|
def _referenced_extract_ids(data: Any, key: str, found: set[str]) -> None:
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
"""MQTT Discovery data."""
|
"""MQTT Discovery data."""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||||
|
|
||||||
ReceivePayloadType = Union[str, bytes]
|
ReceivePayloadType = str | bytes
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -9,7 +9,7 @@ import inspect
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Any, Generic, TypeVar, Union
|
from typing import Any, Generic, TypeVar
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE
|
from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE
|
||||||
from homeassistant.core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
|
||||||
|
@ -24,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
STORAGE_SEMAPHORE = "storage_semaphore"
|
STORAGE_SEMAPHORE = "storage_semaphore"
|
||||||
|
|
||||||
_T = TypeVar("_T", bound=Union[Mapping[str, Any], Sequence[Any]])
|
_T = TypeVar("_T", bound=Mapping[str, Any] | Sequence[Any])
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
|
|
@ -8,7 +8,7 @@ from io import StringIO, TextIOWrapper
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, TextIO, TypeVar, Union, overload
|
from typing import Any, TextIO, TypeVar, overload
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ from .objects import Input, NodeListClass, NodeStrClass
|
||||||
|
|
||||||
# mypy: allow-untyped-calls, no-warn-return-any
|
# mypy: allow-untyped-calls, no-warn-return-any
|
||||||
|
|
||||||
JSON_TYPE = Union[list, dict, str] # pylint: disable=invalid-name
|
JSON_TYPE = list | dict | str # pylint: disable=invalid-name
|
||||||
_DictT = TypeVar("_DictT", bound=dict)
|
_DictT = TypeVar("_DictT", bound=dict)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -154,7 +154,7 @@ class SafeLineLoader(yaml.SafeLoader):
|
||||||
return getattr(self.stream, "name", "")
|
return getattr(self.stream, "name", "")
|
||||||
|
|
||||||
|
|
||||||
LoaderType = Union[SafeLineLoader, SafeLoader]
|
LoaderType = SafeLineLoader | SafeLoader
|
||||||
|
|
||||||
|
|
||||||
def load_yaml(fname: str, secrets: Secrets | None = None) -> JSON_TYPE:
|
def load_yaml(fname: str, secrets: Secrets | None = None) -> JSON_TYPE:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue