mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Rename existing TypeVars referencing Self type (#75473)
This commit is contained in:
parent
b04c3e9adc
commit
d09fff595c
@ -4,15 +4,15 @@ from __future__ import annotations
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, TypeVar
|
from typing import Any, TypeVar
|
||||||
|
|
||||||
_StrEnumT = TypeVar("_StrEnumT", bound="StrEnum")
|
_StrEnumSelfT = TypeVar("_StrEnumSelfT", bound="StrEnum")
|
||||||
|
|
||||||
|
|
||||||
class StrEnum(str, Enum):
|
class StrEnum(str, Enum):
|
||||||
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
|
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
|
||||||
|
|
||||||
def __new__(
|
def __new__(
|
||||||
cls: type[_StrEnumT], value: str, *args: Any, **kwargs: Any
|
cls: type[_StrEnumSelfT], value: str, *args: Any, **kwargs: Any
|
||||||
) -> _StrEnumT:
|
) -> _StrEnumSelfT:
|
||||||
"""Create a new StrEnum instance."""
|
"""Create a new StrEnum instance."""
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
raise TypeError(f"{value!r} is not a string")
|
raise TypeError(f"{value!r} is not a string")
|
||||||
|
@ -58,7 +58,7 @@ from .entry_data import RuntimeEntryData
|
|||||||
DOMAIN = "esphome"
|
DOMAIN = "esphome"
|
||||||
CONF_NOISE_PSK = "noise_psk"
|
CONF_NOISE_PSK = "noise_psk"
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_T = TypeVar("_T")
|
_DomainDataSelfT = TypeVar("_DomainDataSelfT", bound="DomainData")
|
||||||
|
|
||||||
STORAGE_VERSION = 1
|
STORAGE_VERSION = 1
|
||||||
|
|
||||||
@ -101,11 +101,11 @@ class DomainData:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls: type[_T], hass: HomeAssistant) -> _T:
|
def get(cls: type[_DomainDataSelfT], hass: HomeAssistant) -> _DomainDataSelfT:
|
||||||
"""Get the global DomainData instance stored in hass.data."""
|
"""Get the global DomainData instance stored in hass.data."""
|
||||||
# Don't use setdefault - this is a hot code path
|
# Don't use setdefault - this is a hot code path
|
||||||
if DOMAIN in hass.data:
|
if DOMAIN in hass.data:
|
||||||
return cast(_T, hass.data[DOMAIN])
|
return cast(_DomainDataSelfT, hass.data[DOMAIN])
|
||||||
ret = hass.data[DOMAIN] = cls()
|
ret = hass.data[DOMAIN] = cls()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ if TYPE_CHECKING:
|
|||||||
from ...entity import ZhaEntity
|
from ...entity import ZhaEntity
|
||||||
from ..device import ZHADevice
|
from ..device import ZHADevice
|
||||||
|
|
||||||
_ChannelsT = TypeVar("_ChannelsT", bound="Channels")
|
_ChannelsSelfT = TypeVar("_ChannelsSelfT", bound="Channels")
|
||||||
_ChannelPoolT = TypeVar("_ChannelPoolT", bound="ChannelPool")
|
_ChannelPoolSelfT = TypeVar("_ChannelPoolSelfT", bound="ChannelPool")
|
||||||
_ChannelsDictType = dict[str, base.ZigbeeChannel]
|
_ChannelsDictType = dict[str, base.ZigbeeChannel]
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class Channels:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls: type[_ChannelsT], zha_device: ZHADevice) -> _ChannelsT:
|
def new(cls: type[_ChannelsSelfT], zha_device: ZHADevice) -> _ChannelsSelfT:
|
||||||
"""Create new instance."""
|
"""Create new instance."""
|
||||||
channels = cls(zha_device)
|
channels = cls(zha_device)
|
||||||
for ep_id in sorted(zha_device.device.endpoints):
|
for ep_id in sorted(zha_device.device.endpoints):
|
||||||
@ -272,7 +272,9 @@ class ChannelPool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls: type[_ChannelPoolT], channels: Channels, ep_id: int) -> _ChannelPoolT:
|
def new(
|
||||||
|
cls: type[_ChannelPoolSelfT], channels: Channels, ep_id: int
|
||||||
|
) -> _ChannelPoolSelfT:
|
||||||
"""Create new channels for an endpoint."""
|
"""Create new channels for an endpoint."""
|
||||||
pool = cls(channels, ep_id)
|
pool = cls(channels, ep_id)
|
||||||
pool.add_all_channels()
|
pool.add_all_channels()
|
||||||
|
@ -73,7 +73,7 @@ PATH_CONFIG = ".config_entries.json"
|
|||||||
|
|
||||||
SAVE_DELAY = 1
|
SAVE_DELAY = 1
|
||||||
|
|
||||||
_T = TypeVar("_T", bound="ConfigEntryState")
|
_ConfigEntryStateSelfT = TypeVar("_ConfigEntryStateSelfT", bound="ConfigEntryState")
|
||||||
_R = TypeVar("_R")
|
_R = TypeVar("_R")
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,9 @@ class ConfigEntryState(Enum):
|
|||||||
|
|
||||||
_recoverable: bool
|
_recoverable: bool
|
||||||
|
|
||||||
def __new__(cls: type[_T], value: str, recoverable: bool) -> _T:
|
def __new__(
|
||||||
|
cls: type[_ConfigEntryStateSelfT], value: str, recoverable: bool
|
||||||
|
) -> _ConfigEntryStateSelfT:
|
||||||
"""Create new ConfigEntryState."""
|
"""Create new ConfigEntryState."""
|
||||||
obj = object.__new__(cls)
|
obj = object.__new__(cls)
|
||||||
obj._value_ = value
|
obj._value_ = value
|
||||||
|
@ -32,7 +32,7 @@ STATE_DUMP_INTERVAL = timedelta(minutes=15)
|
|||||||
# How long should a saved state be preserved if the entity no longer exists
|
# How long should a saved state be preserved if the entity no longer exists
|
||||||
STATE_EXPIRATION = timedelta(days=7)
|
STATE_EXPIRATION = timedelta(days=7)
|
||||||
|
|
||||||
_StoredStateT = TypeVar("_StoredStateT", bound="StoredState")
|
_StoredStateSelfT = TypeVar("_StoredStateSelfT", bound="StoredState")
|
||||||
|
|
||||||
|
|
||||||
class ExtraStoredData:
|
class ExtraStoredData:
|
||||||
@ -82,7 +82,7 @@ class StoredState:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls: type[_StoredStateT], json_dict: dict) -> _StoredStateT:
|
def from_dict(cls: type[_StoredStateSelfT], json_dict: dict) -> _StoredStateSelfT:
|
||||||
"""Initialize a stored state from a dict."""
|
"""Initialize a stored state from a dict."""
|
||||||
extra_data_dict = json_dict.get("extra_data")
|
extra_data_dict = json_dict.get("extra_data")
|
||||||
extra_data = RestoredExtraData(extra_data_dict) if extra_data_dict else None
|
extra_data = RestoredExtraData(extra_data_dict) if extra_data_dict else None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user