From 3a72054f930a6c1d4bc1c960a292b79dc7c0e6f2 Mon Sep 17 00:00:00 2001 From: rlippmann <70883373+rlippmann@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:58:28 -0400 Subject: [PATCH] Make dataclasses in HA core slotted (#91208) --- homeassistant/exceptions.py | 8 ++++---- homeassistant/helpers/collection.py | 2 +- homeassistant/helpers/entity.py | 4 ++-- homeassistant/helpers/event.py | 6 +++--- homeassistant/helpers/integration_platform.py | 2 +- homeassistant/helpers/intent.py | 2 +- homeassistant/helpers/issue_registry.py | 2 +- homeassistant/helpers/recorder.py | 2 +- homeassistant/helpers/schema_config_entry_flow.py | 4 ++-- homeassistant/helpers/service.py | 2 +- homeassistant/helpers/service_info/mqtt.py | 2 +- homeassistant/helpers/trigger.py | 2 +- homeassistant/loader.py | 2 +- homeassistant/runner.py | 2 +- homeassistant/util/yaml/objects.py | 2 +- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index 6cc93ef4f66..bfc96eabfdf 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -32,7 +32,7 @@ class TemplateError(HomeAssistantError): super().__init__(f"{exception.__class__.__name__}: {exception}") -@dataclass +@dataclass(slots=True) class ConditionError(HomeAssistantError): """Error during condition evaluation.""" @@ -52,7 +52,7 @@ class ConditionError(HomeAssistantError): return "\n".join(list(self.output(indent=0))) -@dataclass +@dataclass(slots=True) class ConditionErrorMessage(ConditionError): """Condition error message.""" @@ -64,7 +64,7 @@ class ConditionErrorMessage(ConditionError): yield self._indent(indent, f"In '{self.type}' condition: {self.message}") -@dataclass +@dataclass(slots=True) class ConditionErrorIndex(ConditionError): """Condition error with index.""" @@ -87,7 +87,7 @@ class ConditionErrorIndex(ConditionError): yield from self.error.output(indent + 1) -@dataclass +@dataclass(slots=True) class ConditionErrorContainer(ConditionError): """Condition error with subconditions.""" diff --git a/homeassistant/helpers/collection.py b/homeassistant/helpers/collection.py index 4d5dc4012ee..29151221a89 100644 --- a/homeassistant/helpers/collection.py +++ b/homeassistant/helpers/collection.py @@ -35,7 +35,7 @@ CHANGE_REMOVED = "removed" _T = TypeVar("_T") -@dataclass +@dataclass(slots=True) class CollectionChangeSet: """Class to represent a change set. diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 8352c1e4463..e5ef3bd4574 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -205,7 +205,7 @@ class EntityPlatformState(Enum): REMOVED = auto() -@dataclass +@dataclass(slots=True) class EntityDescription: """A class that describes Home Assistant entities.""" @@ -981,7 +981,7 @@ class Entity(ABC): return report_issue -@dataclass +@dataclass(slots=True) class ToggleEntityDescription(EntityDescription): """A class that describes toggle entities.""" diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 44a9cb087e3..27258d262ba 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -66,7 +66,7 @@ RANDOM_MICROSECOND_MAX = 500000 _P = ParamSpec("_P") -@dataclass +@dataclass(slots=True) class TrackStates: """Class for keeping track of states being tracked. @@ -80,7 +80,7 @@ class TrackStates: domains: set[str] -@dataclass +@dataclass(slots=True) class TrackTemplate: """Class for keeping track of a template with variables. @@ -94,7 +94,7 @@ class TrackTemplate: rate_limit: timedelta | None = None -@dataclass +@dataclass(slots=True) class TrackTemplateResult: """Class for result of template tracking. diff --git a/homeassistant/helpers/integration_platform.py b/homeassistant/helpers/integration_platform.py index ef05dae518b..ddaede44962 100644 --- a/homeassistant/helpers/integration_platform.py +++ b/homeassistant/helpers/integration_platform.py @@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) DATA_INTEGRATION_PLATFORMS = "integration_platforms" -@dataclass(frozen=True) +@dataclass(slots=True, frozen=True) class IntegrationPlatform: """An integration platform.""" diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index 4e7dcc5a5a1..7a4ca862ee2 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -568,7 +568,7 @@ class IntentResponseTargetType(str, Enum): CUSTOM = "custom" -@dataclass +@dataclass(slots=True) class IntentResponseTarget: """Target of the intent response.""" diff --git a/homeassistant/helpers/issue_registry.py b/homeassistant/helpers/issue_registry.py index 345ec099d3f..afe2d98ed0b 100644 --- a/homeassistant/helpers/issue_registry.py +++ b/homeassistant/helpers/issue_registry.py @@ -32,7 +32,7 @@ class IssueSeverity(StrEnum): WARNING = "warning" -@dataclasses.dataclass(frozen=True) +@dataclasses.dataclass(slots=True, frozen=True) class IssueEntry: """Issue Registry Entry.""" diff --git a/homeassistant/helpers/recorder.py b/homeassistant/helpers/recorder.py index 5545aa09f01..74ebbe5c67a 100644 --- a/homeassistant/helpers/recorder.py +++ b/homeassistant/helpers/recorder.py @@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant, callback DOMAIN = "recorder" -@dataclass +@dataclass(slots=True) class RecorderData: """Recorder data stored in hass.data.""" diff --git a/homeassistant/helpers/schema_config_entry_flow.py b/homeassistant/helpers/schema_config_entry_flow.py index 5101e5c69a7..653594f2808 100644 --- a/homeassistant/helpers/schema_config_entry_flow.py +++ b/homeassistant/helpers/schema_config_entry_flow.py @@ -27,7 +27,7 @@ class SchemaFlowStep: """Define a config or options flow step.""" -@dataclass +@dataclass(slots=True) class SchemaFlowFormStep(SchemaFlowStep): """Define a config or options flow form step.""" @@ -79,7 +79,7 @@ class SchemaFlowFormStep(SchemaFlowStep): """ -@dataclass +@dataclass(slots=True) class SchemaFlowMenuStep(SchemaFlowStep): """Define a config or options flow menu step.""" diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 33c677454bc..14cf6a85a24 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -199,7 +199,7 @@ class ServiceTargetSelector: return bool(self.entity_ids or self.device_ids or self.area_ids) -@dataclasses.dataclass +@dataclasses.dataclass(slots=True) class SelectedEntities: """Class to hold the selected entities.""" diff --git a/homeassistant/helpers/service_info/mqtt.py b/homeassistant/helpers/service_info/mqtt.py index 3626f9b5758..906072a2d4b 100644 --- a/homeassistant/helpers/service_info/mqtt.py +++ b/homeassistant/helpers/service_info/mqtt.py @@ -7,7 +7,7 @@ from homeassistant.data_entry_flow import BaseServiceInfo ReceivePayloadType = str | bytes -@dataclass +@dataclass(slots=True) class MqttServiceInfo(BaseServiceInfo): """Prepared info from mqtt entries.""" diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index e2963b15ab4..40e1860b409 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -95,7 +95,7 @@ class TriggerInfo(TypedDict): trigger_data: TriggerData -@dataclass +@dataclass(slots=True) class PluggableActionsEntry: """Holder to keep track of all plugs and actions for a given trigger.""" diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 11f551b37eb..963ddcf48fc 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -123,7 +123,7 @@ class USBMatcher(USBMatcherRequired, USBMatcherOptional): """Matcher for the bluetooth integration.""" -@dataclass +@dataclass(slots=True) class HomeKitDiscoveredIntegration: """HomeKit model.""" diff --git a/homeassistant/runner.py b/homeassistant/runner.py index e5a87a4b092..9a86bed7594 100644 --- a/homeassistant/runner.py +++ b/homeassistant/runner.py @@ -34,7 +34,7 @@ ALPINE_RELEASE_FILE = "/etc/alpine-release" _LOGGER = logging.getLogger(__name__) -@dataclasses.dataclass +@dataclasses.dataclass(slots=True) class RuntimeConfig: """Class to hold the information for running Home Assistant.""" diff --git a/homeassistant/util/yaml/objects.py b/homeassistant/util/yaml/objects.py index e7b262ad496..b2320a74d2c 100644 --- a/homeassistant/util/yaml/objects.py +++ b/homeassistant/util/yaml/objects.py @@ -18,7 +18,7 @@ class NodeDictClass(dict): """Wrapper class to be able to add attributes on a dict.""" -@dataclass(frozen=True) +@dataclass(slots=True, frozen=True) class Input: """Input that should be substituted."""