Update Union typing (2) [Py310] (#86425)

This commit is contained in:
Marc Mueller 2023-01-23 08:40:09 +01:00 committed by GitHub
parent 1eec87214f
commit f57c0ea725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 29 additions and 36 deletions

View File

@ -6,7 +6,7 @@ import asyncio
from collections.abc import Iterable from collections.abc import Iterable
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
from typing import Any, Union, cast from typing import Any, cast
from gcal_sync.api import ( from gcal_sync.api import (
GoogleCalendarService, GoogleCalendarService,
@ -392,9 +392,7 @@ class CalendarQueryUpdateCoordinator(DataUpdateCoordinator[list[Event]]):
class GoogleCalendarEntity( class GoogleCalendarEntity(
CoordinatorEntity[ CoordinatorEntity[CalendarSyncUpdateCoordinator | CalendarQueryUpdateCoordinator],
Union[CalendarSyncUpdateCoordinator, CalendarQueryUpdateCoordinator]
],
CalendarEntity, CalendarEntity,
): ):
"""A calendar event entity.""" """A calendar event entity."""

View File

@ -1,7 +1,7 @@
"""Support for the sensors in a GreenEye Monitor.""" """Support for the sensors in a GreenEye Monitor."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Union from typing import Any
import greeneye import greeneye
@ -116,12 +116,12 @@ async def async_setup_platform(
on_new_monitor(monitor) on_new_monitor(monitor)
UnderlyingSensorType = Union[ UnderlyingSensorType = (
greeneye.monitor.Channel, greeneye.monitor.Channel
greeneye.monitor.PulseCounter, | greeneye.monitor.PulseCounter
greeneye.monitor.TemperatureSensor, | greeneye.monitor.TemperatureSensor
greeneye.monitor.VoltageSensor, | greeneye.monitor.VoltageSensor
] )
class GEMSensor(SensorEntity): class GEMSensor(SensorEntity):

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import timedelta from datetime import timedelta
from typing import Any, TypeVar, Union from typing import Any, TypeVar
from jellyfin_apiclient_python import JellyfinClient from jellyfin_apiclient_python import JellyfinClient
@ -15,10 +15,7 @@ from .const import DOMAIN, LOGGER
JellyfinDataT = TypeVar( JellyfinDataT = TypeVar(
"JellyfinDataT", "JellyfinDataT",
bound=Union[ bound=dict[str, dict[str, Any]] | dict[str, Any],
dict[str, dict[str, Any]],
dict[str, Any],
],
) )

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import timedelta from datetime import timedelta
from typing import Generic, TypeVar, Union, cast from typing import Generic, TypeVar, cast
from aiopyarr import LidarrAlbum, LidarrQueue, LidarrRootFolder, exceptions from aiopyarr import LidarrAlbum, LidarrQueue, LidarrRootFolder, exceptions
from aiopyarr.lidarr_client import LidarrClient from aiopyarr.lidarr_client import LidarrClient
@ -16,7 +16,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DEFAULT_MAX_RECORDS, DOMAIN, LOGGER from .const import DEFAULT_MAX_RECORDS, DOMAIN, LOGGER
T = TypeVar("T", bound=Union[list[LidarrRootFolder], LidarrQueue, str, LidarrAlbum]) T = TypeVar("T", bound=list[LidarrRootFolder] | LidarrQueue | str | LidarrAlbum)
class LidarrDataUpdateCoordinator(DataUpdateCoordinator[T], Generic[T], ABC): class LidarrDataUpdateCoordinator(DataUpdateCoordinator[T], Generic[T], ABC):

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from typing import Any, Generic, Union, cast from typing import Any, Generic, cast
from pylitterbot import FeederRobot, LitterRobot, LitterRobot4, Robot from pylitterbot import FeederRobot, LitterRobot, LitterRobot4, Robot
@ -55,7 +55,7 @@ class LitterRobotSensorEntity(LitterRobotEntity[_RobotT], SensorEntity):
if self.entity_description.should_report(self.robot): if self.entity_description.should_report(self.robot):
if isinstance(val := getattr(self.robot, self.entity_description.key), str): if isinstance(val := getattr(self.robot, self.entity_description.key), str):
return val.lower() return val.lower()
return cast(Union[float, datetime, None], val) return cast(float | datetime | None, val)
return None return None
@property @property

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable, Coroutine from collections.abc import Callable, Coroutine
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Generic, Union from typing import Any, Generic
from pylitterbot import FeederRobot, LitterRobot from pylitterbot import FeederRobot, LitterRobot
@ -34,13 +34,13 @@ class RobotSwitchEntityDescription(SwitchEntityDescription, RequiredKeysMixin[_R
ROBOT_SWITCHES = [ ROBOT_SWITCHES = [
RobotSwitchEntityDescription[Union[LitterRobot, FeederRobot]]( RobotSwitchEntityDescription[LitterRobot | FeederRobot](
key="night_light_mode_enabled", key="night_light_mode_enabled",
name="Night light mode", name="Night light mode",
icons=("mdi:lightbulb-on", "mdi:lightbulb-off"), icons=("mdi:lightbulb-on", "mdi:lightbulb-off"),
set_fn=lambda robot, value: robot.set_night_light(value), set_fn=lambda robot, value: robot.set_night_light(value),
), ),
RobotSwitchEntityDescription[Union[LitterRobot, FeederRobot]]( RobotSwitchEntityDescription[LitterRobot | FeederRobot](
key="panel_lock_enabled", key="panel_lock_enabled",
name="Panel lockout", name="Panel lockout",
icons=("mdi:lock", "mdi:lock-open"), icons=("mdi:lock", "mdi:lock-open"),

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, TypeVar, Union from typing import Any, TypeVar
from meteofrance_api.helpers import ( from meteofrance_api.helpers import (
get_warning_text_status_from_indice_color, get_warning_text_status_from_indice_color,
@ -49,7 +49,7 @@ from .const import (
MODEL, MODEL,
) )
_DataT = TypeVar("_DataT", bound=Union[Rain, Forecast, CurrentPhenomenons]) _DataT = TypeVar("_DataT", bound=Rain | Forecast | CurrentPhenomenons)
@dataclass @dataclass

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import timedelta from datetime import timedelta
from typing import Generic, TypeVar, Union, cast from typing import Generic, TypeVar, cast
from aiopyarr import Health, RadarrMovie, RootFolder, SystemStatus, exceptions from aiopyarr import Health, RadarrMovie, RootFolder, SystemStatus, exceptions
from aiopyarr.models.host_configuration import PyArrHostConfiguration from aiopyarr.models.host_configuration import PyArrHostConfiguration
@ -16,7 +16,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DOMAIN, LOGGER from .const import DOMAIN, LOGGER
T = TypeVar("T", bound=Union[SystemStatus, list[RootFolder], list[Health], int]) T = TypeVar("T", bound=SystemStatus | list[RootFolder] | list[Health] | int)
class RadarrDataUpdateCoordinator(DataUpdateCoordinator[T], Generic[T], ABC): class RadarrDataUpdateCoordinator(DataUpdateCoordinator[T], Generic[T], ABC):

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable, Coroutine from collections.abc import Callable, Coroutine
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Final, Generic, TypeVar, Union from typing import Any, Final, Generic, TypeVar
from homeassistant.components.button import ( from homeassistant.components.button import (
ButtonDeviceClass, ButtonDeviceClass,
@ -23,7 +23,7 @@ from .coordinator import ShellyBlockCoordinator, ShellyRpcCoordinator, get_entry
from .utils import get_block_device_name, get_device_entry_gen, get_rpc_device_name from .utils import get_block_device_name, get_device_entry_gen, get_rpc_device_name
_ShellyCoordinatorT = TypeVar( _ShellyCoordinatorT = TypeVar(
"_ShellyCoordinatorT", bound=Union[ShellyBlockCoordinator, ShellyRpcCoordinator] "_ShellyCoordinatorT", bound=ShellyBlockCoordinator | ShellyRpcCoordinator
) )
@ -44,7 +44,7 @@ class ShellyButtonDescription(
BUTTONS: Final[list[ShellyButtonDescription[Any]]] = [ BUTTONS: Final[list[ShellyButtonDescription[Any]]] = [
ShellyButtonDescription[Union[ShellyBlockCoordinator, ShellyRpcCoordinator]]( ShellyButtonDescription[ShellyBlockCoordinator | ShellyRpcCoordinator](
key="reboot", key="reboot",
name="Reboot", name="Reboot",
device_class=ButtonDeviceClass.RESTART, device_class=ButtonDeviceClass.RESTART,
@ -102,7 +102,7 @@ async def async_setup_entry(
class ShellyButton( class ShellyButton(
CoordinatorEntity[Union[ShellyRpcCoordinator, ShellyBlockCoordinator]], ButtonEntity CoordinatorEntity[ShellyRpcCoordinator | ShellyBlockCoordinator], ButtonEntity
): ):
"""Defines a Shelly base button.""" """Defines a Shelly base button."""

View File

@ -1,7 +1,5 @@
"""Define typing helpers for SimpliSafe.""" """Define typing helpers for SimpliSafe."""
from typing import Union
from simplipy.system.v2 import SystemV2 from simplipy.system.v2 import SystemV2
from simplipy.system.v3 import SystemV3 from simplipy.system.v3 import SystemV3
SystemType = Union[SystemV2, SystemV3] SystemType = SystemV2 | SystemV3

View File

@ -1,6 +1,6 @@
"""Entity for the SleepIQ integration.""" """Entity for the SleepIQ integration."""
from abc import abstractmethod from abc import abstractmethod
from typing import TypeVar, Union from typing import TypeVar
from asyncsleepiq import SleepIQBed, SleepIQSleeper from asyncsleepiq import SleepIQBed, SleepIQSleeper
@ -14,7 +14,7 @@ from .coordinator import SleepIQDataUpdateCoordinator, SleepIQPauseUpdateCoordin
_SleepIQCoordinatorT = TypeVar( _SleepIQCoordinatorT = TypeVar(
"_SleepIQCoordinatorT", "_SleepIQCoordinatorT",
bound=Union[SleepIQDataUpdateCoordinator, SleepIQPauseUpdateCoordinator], bound=SleepIQDataUpdateCoordinator | SleepIQPauseUpdateCoordinator,
) )