Skip to content

Commit

Permalink
Use PEP 695 for simple type aliases (#117633)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored May 17, 2024
1 parent 4edee94 commit 87bb7ce
Show file tree
Hide file tree
Showing 78 changed files with 139 additions and 140 deletions.
6 changes: 3 additions & 3 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
EVENT_USER_UPDATED = "user_updated"
EVENT_USER_REMOVED = "user_removed"

_MfaModuleDict = dict[str, MultiFactorAuthModule]
_ProviderKey = tuple[str, str | None]
_ProviderDict = dict[_ProviderKey, AuthProvider]
type _MfaModuleDict = dict[str, MultiFactorAuthModule]
type _ProviderKey = tuple[str, str | None]
type _ProviderDict = dict[_ProviderKey, AuthProvider]


class InvalidAuthError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/mfa_modules/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class NotifySetting:
target: str | None = attr.ib(default=None)


_UsersDict = dict[str, NotifySetting]
type _UsersDict = dict[str, NotifySetting]


@MULTI_FACTOR_AUTH_MODULES.register("notify")
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/auth/permissions/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

# MyPy doesn't support recursion yet. So writing it out as far as we need.

ValueType = (
type ValueType = (
# Example: entities.all = { read: true, control: true }
Mapping[str, bool] | bool | None
)

# Example: entities.domains = { light: … }
SubCategoryDict = Mapping[str, ValueType]
type SubCategoryDict = Mapping[str, ValueType]

SubCategoryType = SubCategoryDict | bool | None
type SubCategoryType = SubCategoryDict | bool | None

CategoryType = (
type CategoryType = (
# Example: entities.domains
Mapping[str, SubCategoryType]
# Example: entities.all
Expand All @@ -24,4 +24,4 @@
)

# Example: { entities: … }
PolicyType = Mapping[str, CategoryType]
type PolicyType = Mapping[str, CategoryType]
4 changes: 2 additions & 2 deletions homeassistant/auth/permissions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from .models import PermissionLookup
from .types import CategoryType, SubCategoryDict, ValueType

LookupFunc = Callable[[PermissionLookup, SubCategoryDict, str], ValueType | None]
SubCatLookupType = dict[str, LookupFunc]
type LookupFunc = Callable[[PermissionLookup, SubCategoryDict, str], ValueType | None]
type SubCatLookupType = dict[str, LookupFunc]


def lookup_all(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/auth/providers/trusted_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from ..models import AuthFlowResult, Credentials, RefreshToken, UserMeta
from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow

IPAddress = IPv4Address | IPv6Address
IPNetwork = IPv4Network | IPv6Network
type IPAddress = IPv4Address | IPv6Address
type IPNetwork = IPv4Network | IPv6Network

CONF_TRUSTED_NETWORKS = "trusted_networks"
CONF_TRUSTED_USERS = "trusted_users"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class PipelineEvent:
timestamp: str = field(default_factory=lambda: dt_util.utcnow().isoformat())


PipelineEventCallback = Callable[[PipelineEvent], None]
type PipelineEventCallback = Callable[[PipelineEvent], None]


@dataclass(frozen=True)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
DOMAIN = "auth"
STRICT_CONNECTION_URL = "/auth/strict_connection/temp_token"

StoreResultType = Callable[[str, Credentials], str]
RetrieveResultType = Callable[[str, str], Credentials | None]
type StoreResultType = Callable[[str, Credentials], str]
type RetrieveResultType = Callable[[str, str], Credentials | None]

CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/bluetooth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
from home_assistant_bluetooth import BluetoothServiceInfoBleak

BluetoothChange = Enum("BluetoothChange", "ADVERTISEMENT")
BluetoothCallback = Callable[[BluetoothServiceInfoBleak, BluetoothChange], None]
ProcessAdvertisementCallback = Callable[[BluetoothServiceInfoBleak], bool]
type BluetoothCallback = Callable[[BluetoothServiceInfoBleak, BluetoothChange], None]
type ProcessAdvertisementCallback = Callable[[BluetoothServiceInfoBleak], bool]
4 changes: 2 additions & 2 deletions homeassistant/components/calendar/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def __str__(self) -> str:
return f"[{self.start}, {self.end})"


EventFetcher = Callable[[Timespan], Awaitable[list[CalendarEvent]]]
QueuedEventFetcher = Callable[[Timespan], Awaitable[list[QueuedCalendarEvent]]]
type EventFetcher = Callable[[Timespan], Awaitable[list[CalendarEvent]]]
type QueuedEventFetcher = Callable[[Timespan], Awaitable[list[QueuedCalendarEvent]]]


def get_entity(hass: HomeAssistant, entity_id: str) -> CalendarEntity:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _get_camera_from_entity_id(hass: HomeAssistant, entity_id: str) -> Camera:
# stream_id: A unique id for the stream, used to update an existing source
# The output is the SDP answer, or None if the source or offer is not eligible.
# The Callable may throw HomeAssistantError on failure.
RtspToWebRtcProviderType = Callable[[str, str, str], Awaitable[str | None]]
type RtspToWebRtcProviderType = Callable[[str, str, str], Awaitable[str | None]]


def async_register_rtsp_to_web_rtc_provider(
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/canary/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from .const import DATA_COORDINATOR, DOMAIN, MANUFACTURER
from .coordinator import CanaryDataUpdateCoordinator

SensorTypeItem = tuple[str, str | None, str | None, SensorDeviceClass | None, list[str]]
type SensorTypeItem = tuple[
str, str | None, str | None, SensorDeviceClass | None, list[str]
]

SENSOR_VALUE_PRECISION: Final = 2
ATTR_AIR_QUALITY: Final = "air_quality"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/configurator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
STATE_CONFIGURE = "configure"
STATE_CONFIGURED = "configured"

ConfiguratorCallback = Callable[[list[dict[str, str]]], None]
type ConfiguratorCallback = Callable[[list[dict[str, str]]], None]

CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/device_automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import wraps
import logging
from types import ModuleType
from typing import TYPE_CHECKING, Any, Literal, TypeAlias, overload
from typing import TYPE_CHECKING, Any, Literal, overload

import voluptuous as vol
import voluptuous_serialize
Expand Down Expand Up @@ -49,7 +49,7 @@
from .condition import DeviceAutomationConditionProtocol
from .trigger import DeviceAutomationTriggerProtocol

DeviceAutomationPlatformType: TypeAlias = (
type DeviceAutomationPlatformType = (
ModuleType
| DeviceAutomationTriggerProtocol
| DeviceAutomationConditionProtocol
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/dlna_dmr/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

LOGGER = logging.getLogger(__name__)

FlowInput = Mapping[str, Any] | None
type FlowInput = Mapping[str, Any] | None


class ConnectError(IntegrationError):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/energy/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class WaterSourceType(TypedDict):
number_energy_price: float | None # Price for energy ($/m³)


SourceType = (
type SourceType = (
GridSourceType
| SolarSourceType
| BatterySourceType
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/energy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class SolarForecastType(TypedDict):
wh_hours: dict[str, float | int]


GetSolarForecastType = Callable[
[HomeAssistant, str], Awaitable["SolarForecastType | None"]
type GetSolarForecastType = Callable[
[HomeAssistant, str], Awaitable[SolarForecastType | None]
]


Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/energy/websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
from .types import EnergyPlatform, GetSolarForecastType, SolarForecastType
from .validate import async_validate

EnergyWebSocketCommandHandler = Callable[
[HomeAssistant, websocket_api.ActiveConnection, "dict[str, Any]", "EnergyManager"],
type EnergyWebSocketCommandHandler = Callable[
[HomeAssistant, websocket_api.ActiveConnection, dict[str, Any], EnergyManager],
None,
]
AsyncEnergyWebSocketCommandHandler = Callable[
[HomeAssistant, websocket_api.ActiveConnection, "dict[str, Any]", "EnergyManager"],
type AsyncEnergyWebSocketCommandHandler = Callable[
[HomeAssistant, websocket_api.ActiveConnection, dict[str, Any], EnergyManager],
Awaitable[None],
]

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/firmata/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

_LOGGER = logging.getLogger(__name__)

FirmataPinType = int | str
type FirmataPinType = int | str


class FirmataBoard:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/fronius/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

DOMAIN: Final = "fronius"

SolarNetId = str
type SolarNetId = str
SOLAR_NET_DISCOVERY_NEW: Final = "fronius_discovery_new"
SOLAR_NET_ID_POWER_FLOW: SolarNetId = "power_flow"
SOLAR_NET_ID_SYSTEM: SolarNetId = "system"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/greeneye_monitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def on_new_monitor(monitor: greeneye.monitor.Monitor) -> None:
on_new_monitor(monitor)


UnderlyingSensorType = (
type UnderlyingSensorType = (
greeneye.monitor.Channel
| greeneye.monitor.PulseCounter
| greeneye.monitor.TemperatureSensor
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/harmony/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

_LOGGER = logging.getLogger(__name__)

NoParamCallback = HassJob[[], Any] | None
ActivityCallback = HassJob[[tuple], Any] | None
type NoParamCallback = HassJob[[], Any] | None
type ActivityCallback = HassJob[[tuple], Any] | None


class HarmonyCallback(NamedTuple):
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/homekit_controller/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@

_LOGGER = logging.getLogger(__name__)

AddAccessoryCb = Callable[[Accessory], bool]
AddServiceCb = Callable[[Service], bool]
AddCharacteristicCb = Callable[[Characteristic], bool]
type AddAccessoryCb = Callable[[Accessory], bool]
type AddServiceCb = Callable[[Service], bool]
type AddCharacteristicCb = Callable[[Characteristic], bool]


def valid_serial_number(serial: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homekit_controller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .const import CONTROLLER
from .storage import async_get_entity_storage

IidTuple = tuple[int, int | None, int | None]
type IidTuple = tuple[int, int | None, int | None]


def unique_id_to_iids(unique_id: str) -> IidTuple | None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/huawei_lte/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

_DEVICE_SCAN = f"{DEVICE_TRACKER_DOMAIN}/device_scan"

_HostType = dict[str, Any]
type _HostType = dict[str, Any]


def _get_hosts(
Expand Down
7 changes: 2 additions & 5 deletions homeassistant/components/hue/v2/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from functools import partial
from typing import TypeAlias

from aiohue.v2 import HueBridgeV2
from aiohue.v2.controllers.config import (
Expand Down Expand Up @@ -37,10 +36,8 @@
from ..const import DOMAIN
from .entity import HueBaseEntity

SensorType: TypeAlias = (
CameraMotion | Contact | Motion | EntertainmentConfiguration | Tamper
)
ControllerType: TypeAlias = (
type SensorType = CameraMotion | Contact | Motion | EntertainmentConfiguration | Tamper
type ControllerType = (
CameraMotionController
| ContactController
| MotionController
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hue/v2/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, TypeAlias
from typing import TYPE_CHECKING

from aiohue.v2.controllers.base import BaseResourcesController
from aiohue.v2.controllers.events import EventType
Expand All @@ -24,7 +24,7 @@
from aiohue.v2.models.light_level import LightLevel
from aiohue.v2.models.motion import Motion

HueResource: TypeAlias = Light | DevicePower | GroupedLight | LightLevel | Motion
type HueResource = Light | DevicePower | GroupedLight | LightLevel | Motion


RESOURCE_TYPE_NAMES = {
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/hue/v2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from functools import partial
from typing import Any, TypeAlias
from typing import Any

from aiohue.v2 import HueBridgeV2
from aiohue.v2.controllers.events import EventType
Expand Down Expand Up @@ -34,8 +34,8 @@
from ..const import DOMAIN
from .entity import HueBaseEntity

SensorType: TypeAlias = DevicePower | LightLevel | Temperature | ZigbeeConnectivity
ControllerType: TypeAlias = (
type SensorType = DevicePower | LightLevel | Temperature | ZigbeeConnectivity
type ControllerType = (
DevicePowerController
| LightLevelController
| TemperatureController
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/intent/timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class TimerEventType(StrEnum):
"""Timer finished without being cancelled."""


TimerHandler = Callable[[TimerEventType, TimerInfo], None]
type TimerHandler = Callable[[TimerEventType, TimerInfo], None]


class TimerNotFoundError(intent.IntentHandleError):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/knx/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
# dispatcher signal for KNX interface device triggers
SIGNAL_KNX_TELEGRAM_DICT: Final = "knx_telegram_dict"

AsyncMessageCallbackType = Callable[[Telegram], Awaitable[None]]
MessageCallbackType = Callable[[Telegram], None]
type AsyncMessageCallbackType = Callable[[Telegram], Awaitable[None]]
type MessageCallbackType = Callable[[Telegram], None]

SERVICE_KNX_SEND: Final = "send"
SERVICE_KNX_ATTR_PAYLOAD: Final = "payload"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/kraken/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KrakenResponseEntry(TypedDict):
opening_price: float


KrakenResponse = dict[str, KrakenResponseEntry]
type KrakenResponse = dict[str, KrakenResponseEntry]


DEFAULT_SCAN_INTERVAL = 60
Expand Down
10 changes: 4 additions & 6 deletions homeassistant/components/lcn/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from copy import deepcopy
from itertools import chain
import re
from typing import TypeAlias, cast
from typing import cast

import pypck
import voluptuous as vol
Expand Down Expand Up @@ -60,12 +60,10 @@
)

# typing
AddressType = tuple[int, int, bool]
DeviceConnectionType: TypeAlias = (
pypck.module.ModuleConnection | pypck.module.GroupConnection
)
type AddressType = tuple[int, int, bool]
type DeviceConnectionType = pypck.module.ModuleConnection | pypck.module.GroupConnection

InputType = type[pypck.inputs.Input]
type InputType = type[pypck.inputs.Input]

# Regex for address validation
PATTERN_ADDRESS = re.compile(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/matter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.const import Platform
from homeassistant.helpers.entity import EntityDescription

SensorValueTypes = type[
type SensorValueTypes = type[
clusters.uint | int | clusters.Nullable | clusters.float32 | float
]

Expand Down
Loading

0 comments on commit 87bb7ce

Please sign in to comment.