Enable RUF023 (#135830)

This commit is contained in:
Joost Lekkerkerker 2025-01-17 12:28:27 +01:00 committed by GitHub
parent 23e04ced9c
commit ef8b8fbbaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 105 additions and 104 deletions

View File

@ -50,11 +50,11 @@ class HomeAssistantBluetoothManager(BluetoothManager):
"""Manage Bluetooth for Home Assistant.""" """Manage Bluetooth for Home Assistant."""
__slots__ = ( __slots__ = (
"hass",
"storage",
"_integration_matcher",
"_callback_index", "_callback_index",
"_cancel_logging_listener", "_cancel_logging_listener",
"_integration_matcher",
"hass",
"storage",
) )
def __init__( def __init__(

View File

@ -92,7 +92,7 @@ def seen_all_fields(
class IntegrationMatcher: class IntegrationMatcher:
"""Integration matcher for the bluetooth integration.""" """Integration matcher for the bluetooth integration."""
__slots__ = ("_integration_matchers", "_matched", "_matched_connectable", "_index") __slots__ = ("_index", "_integration_matchers", "_matched", "_matched_connectable")
def __init__(self, integration_matchers: list[BluetoothMatcher]) -> None: def __init__(self, integration_matchers: list[BluetoothMatcher]) -> None:
"""Initialize the matcher.""" """Initialize the matcher."""
@ -164,12 +164,12 @@ class BluetoothMatcherIndexBase[
__slots__ = ( __slots__ = (
"local_name", "local_name",
"service_uuid",
"service_data_uuid",
"manufacturer_id", "manufacturer_id",
"service_uuid_set",
"service_data_uuid_set",
"manufacturer_id_set", "manufacturer_id_set",
"service_data_uuid",
"service_data_uuid_set",
"service_uuid",
"service_uuid_set",
) )
def __init__(self) -> None: def __init__(self) -> None:

View File

@ -134,16 +134,16 @@ class ESPHomeManager:
"""Class to manage an ESPHome connection.""" """Class to manage an ESPHome connection."""
__slots__ = ( __slots__ = (
"hass",
"host",
"password",
"entry",
"cli", "cli",
"device_id", "device_id",
"domain_data", "domain_data",
"entry",
"entry_data",
"hass",
"host",
"password",
"reconnect_logic", "reconnect_logic",
"zeroconf_instance", "zeroconf_instance",
"entry_data",
) )
def __init__( def __init__(

View File

@ -521,7 +521,7 @@ def supported_traits_for_state(state: State) -> list[type[trait._Trait]]:
class GoogleEntity: class GoogleEntity:
"""Adaptation of Entity expressed in Google's terms.""" """Adaptation of Entity expressed in Google's terms."""
__slots__ = ("hass", "config", "state", "entity_id", "_traits") __slots__ = ("_traits", "config", "entity_id", "hass", "state")
def __init__( def __init__(
self, hass: HomeAssistant, config: AbstractConfig, state: State self, hass: HomeAssistant, config: AbstractConfig, state: State

View File

@ -22,7 +22,7 @@ class HomeAssistantTCPSite(web.BaseSite):
is merged. is merged.
""" """
__slots__ = ("_host", "_port", "_reuse_address", "_reuse_port", "_hosturl") __slots__ = ("_host", "_hosturl", "_port", "_reuse_address", "_reuse_port")
def __init__( def __init__(
self, self,

View File

@ -24,12 +24,12 @@ class LegacyLazyState(State):
"""A lazy version of core State after schema 31.""" """A lazy version of core State after schema 31."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_last_changed_ts",
"_last_updated_ts",
"_last_reported_ts",
"_context", "_context",
"_last_changed_ts",
"_last_reported_ts",
"_last_updated_ts",
"_row",
"attr_cache", "attr_cache",
] ]

View File

@ -163,16 +163,16 @@ class LogEntry:
"""Store HA log entries.""" """Store HA log entries."""
__slots__ = ( __slots__ = (
"count",
"exception",
"first_occurred", "first_occurred",
"timestamp", "key",
"name",
"level", "level",
"message", "message",
"exception", "name",
"root_cause", "root_cause",
"source", "source",
"count", "timestamp",
"key",
) )
def __init__( def __init__(

View File

@ -40,17 +40,17 @@ class ActiveConnection:
"""Handle an active websocket client connection.""" """Handle an active websocket client connection."""
__slots__ = ( __slots__ = (
"logger",
"hass",
"send_message",
"user",
"refresh_token_id",
"subscriptions",
"last_id",
"can_coalesce",
"supported_features",
"handlers",
"binary_handlers", "binary_handlers",
"can_coalesce",
"handlers",
"hass",
"last_id",
"logger",
"refresh_token_id",
"send_message",
"subscriptions",
"supported_features",
"user",
) )
def __init__( def __init__(

View File

@ -70,20 +70,20 @@ class WebSocketHandler:
"""Handle an active websocket client connection.""" """Handle an active websocket client connection."""
__slots__ = ( __slots__ = (
"_hass",
"_loop",
"_request",
"_wsock",
"_handle_task",
"_writer_task",
"_closing",
"_authenticated", "_authenticated",
"_logger", "_closing",
"_peak_checker_unsub",
"_connection", "_connection",
"_handle_task",
"_hass",
"_logger",
"_loop",
"_message_queue", "_message_queue",
"_peak_checker_unsub",
"_ready_future", "_ready_future",
"_release_ready_queue_size", "_release_ready_queue_size",
"_request",
"_writer_task",
"_wsock",
) )
def __init__(self, hass: HomeAssistant, request: web.Request) -> None: def __init__(self, hass: HomeAssistant, request: web.Request) -> None:

View File

@ -332,7 +332,7 @@ class HassJob[**_P, _R_co]:
we run the job. we run the job.
""" """
__slots__ = ("target", "name", "_cancel_on_shutdown", "_cache") __slots__ = ("_cache", "_cancel_on_shutdown", "name", "target")
def __init__( def __init__(
self, self,
@ -1246,7 +1246,7 @@ class HomeAssistant:
class Context: class Context:
"""The context that triggered something.""" """The context that triggered something."""
__slots__ = ("id", "user_id", "parent_id", "origin_event", "_cache") __slots__ = ("_cache", "id", "origin_event", "parent_id", "user_id")
def __init__( def __init__(
self, self,
@ -1321,12 +1321,12 @@ class Event(Generic[_DataT]):
"""Representation of an event within the bus.""" """Representation of an event within the bus."""
__slots__ = ( __slots__ = (
"event_type", "_cache",
"context",
"data", "data",
"event_type",
"origin", "origin",
"time_fired_timestamp", "time_fired_timestamp",
"context",
"_cache",
) )
def __init__( def __init__(
@ -1767,18 +1767,18 @@ class State:
""" """
__slots__ = ( __slots__ = (
"entity_id", "_cache",
"state",
"attributes", "attributes",
"context",
"domain",
"entity_id",
"last_changed", "last_changed",
"last_reported", "last_reported",
"last_updated", "last_updated",
"context",
"state_info",
"domain",
"object_id",
"last_updated_timestamp", "last_updated_timestamp",
"_cache", "object_id",
"state",
"state_info",
) )
def __init__( def __init__(
@ -2066,7 +2066,7 @@ class States(UserDict[str, State]):
class StateMachine: class StateMachine:
"""Helper class that tracks the state of different entities.""" """Helper class that tracks the state of different entities."""
__slots__ = ("_states", "_states_data", "_reservations", "_bus", "_loop") __slots__ = ("_bus", "_loop", "_reservations", "_states", "_states_data")
def __init__(self, bus: EventBus, loop: asyncio.events.AbstractEventLoop) -> None: def __init__(self, bus: EventBus, loop: asyncio.events.AbstractEventLoop) -> None:
"""Initialize state machine.""" """Initialize state machine."""
@ -2404,7 +2404,7 @@ class SupportsResponse(enum.StrEnum):
class Service: class Service:
"""Representation of a callable service.""" """Representation of a callable service."""
__slots__ = ["job", "schema", "domain", "service", "supports_response"] __slots__ = ["domain", "job", "schema", "service", "supports_response"]
def __init__( def __init__(
self, self,
@ -2431,7 +2431,7 @@ class Service:
class ServiceCall: class ServiceCall:
"""Representation of a call to a service.""" """Representation of a call to a service."""
__slots__ = ("hass", "domain", "service", "data", "context", "return_response") __slots__ = ("context", "data", "domain", "hass", "return_response", "service")
def __init__( def __init__(
self, self,
@ -2464,7 +2464,7 @@ class ServiceCall:
class ServiceRegistry: class ServiceRegistry:
"""Offer the services over the eventbus.""" """Offer the services over the eventbus."""
__slots__ = ("_services", "_hass") __slots__ = ("_hass", "_services")
def __init__(self, hass: HomeAssistant) -> None: def __init__(self, hass: HomeAssistant) -> None:
"""Initialize a service registry.""" """Initialize a service registry."""

View File

@ -78,7 +78,7 @@ async def _async_get_component_icons(
class _IconsCache: class _IconsCache:
"""Cache for icons.""" """Cache for icons."""
__slots__ = ("_hass", "_loaded", "_cache", "_lock") __slots__ = ("_cache", "_hass", "_loaded", "_lock")
def __init__(self, hass: HomeAssistant) -> None: def __init__(self, hass: HomeAssistant) -> None:
"""Initialize the cache.""" """Initialize the cache."""

View File

@ -1202,17 +1202,17 @@ class Intent:
"""Hold the intent.""" """Hold the intent."""
__slots__ = [ __slots__ = [
"assistant",
"category",
"context",
"conversation_agent_id",
"device_id",
"hass", "hass",
"platform",
"intent_type", "intent_type",
"language",
"platform",
"slots", "slots",
"text_input", "text_input",
"context",
"language",
"category",
"assistant",
"device_id",
"conversation_agent_id",
] ]
def __init__( def __init__(

View File

@ -225,7 +225,7 @@ class ServiceParams(TypedDict):
class ServiceTargetSelector: class ServiceTargetSelector:
"""Class to hold a target selector for a service.""" """Class to hold a target selector for a service."""
__slots__ = ("entity_ids", "device_ids", "area_ids", "floor_ids", "label_ids") __slots__ = ("area_ids", "device_ids", "entity_ids", "floor_ids", "label_ids")
def __init__(self, service_call: ServiceCall) -> None: def __init__(self, service_call: ServiceCall) -> None:
"""Extract ids from service call data.""" """Extract ids from service call data."""

View File

@ -386,19 +386,19 @@ class RenderInfo:
"""Holds information about a template render.""" """Holds information about a template render."""
__slots__ = ( __slots__ = (
"template",
"filter_lifecycle",
"filter",
"_result", "_result",
"is_static",
"exception",
"all_states", "all_states",
"all_states_lifecycle", "all_states_lifecycle",
"domains", "domains",
"domains_lifecycle", "domains_lifecycle",
"entities", "entities",
"rate_limit", "exception",
"filter",
"filter_lifecycle",
"has_time", "has_time",
"is_static",
"rate_limit",
"template",
) )
def __init__(self, template: Template) -> None: def __init__(self, template: Template) -> None:
@ -507,17 +507,17 @@ class Template:
__slots__ = ( __slots__ = (
"__weakref__", "__weakref__",
"template", "_compiled",
"_compiled_code",
"_exc_info",
"_hash_cache",
"_limited",
"_log_fn",
"_renders",
"_strict",
"hass", "hass",
"is_static", "is_static",
"_compiled_code", "template",
"_compiled",
"_exc_info",
"_limited",
"_strict",
"_log_fn",
"_hash_cache",
"_renders",
) )
def __init__(self, template: str, hass: HomeAssistant | None = None) -> None: def __init__(self, template: str, hass: HomeAssistant | None = None) -> None:
@ -991,7 +991,7 @@ class StateTranslated:
class DomainStates: class DomainStates:
"""Class to expose a specific HA domain as attributes.""" """Class to expose a specific HA domain as attributes."""
__slots__ = ("_hass", "_domain") __slots__ = ("_domain", "_hass")
__setitem__ = _readonly __setitem__ = _readonly
__delitem__ = _readonly __delitem__ = _readonly
@ -1035,7 +1035,7 @@ class DomainStates:
class TemplateStateBase(State): class TemplateStateBase(State):
"""Class to represent a state object in a template.""" """Class to represent a state object in a template."""
__slots__ = ("_hass", "_collect", "_entity_id", "_state") __slots__ = ("_collect", "_entity_id", "_hass", "_state")
_state: State _state: State

View File

@ -23,11 +23,11 @@ class TraceElement:
"_child_run_id", "_child_run_id",
"_error", "_error",
"_last_variables", "_last_variables",
"path",
"_result", "_result",
"reuse_by_child",
"_timestamp", "_timestamp",
"_variables", "_variables",
"path",
"reuse_by_child",
) )
def __init__(self, variables: TemplateVarsType, path: str) -> None: def __init__(self, variables: TemplateVarsType, path: str) -> None:

View File

@ -147,7 +147,7 @@ class _TranslationsCacheData:
class _TranslationCache: class _TranslationCache:
"""Cache for flattened translations.""" """Cache for flattened translations."""
__slots__ = ("hass", "cache_data", "lock") __slots__ = ("cache_data", "hass", "lock")
def __init__(self, hass: HomeAssistant) -> None: def __init__(self, hass: HomeAssistant) -> None:
"""Initialize the cache.""" """Initialize the cache."""

View File

@ -765,6 +765,7 @@ select = [
"RUF020", # {never_like} | T is equivalent to T "RUF020", # {never_like} | T is equivalent to T
"RUF021", # Parenthesize a and b expressions when chaining and and or together, to make the precedence clear "RUF021", # Parenthesize a and b expressions when chaining and and or together, to make the precedence clear
"RUF022", # Sort __all__ "RUF022", # Sort __all__
"RUF023", # Sort __slots__
"RUF024", # Do not pass mutable objects as values to dict.fromkeys "RUF024", # Do not pass mutable objects as values to dict.fromkeys
"RUF026", # default_factory is a positional-only argument to defaultdict "RUF026", # default_factory is a positional-only argument to defaultdict
"RUF030", # print() call in assert statement is likely unintentional "RUF030", # print() call in assert statement is likely unintentional

View File

@ -347,11 +347,11 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
] ]
def __init__(self, row) -> None: # pylint: disable=super-init-not-called def __init__(self, row) -> None: # pylint: disable=super-init-not-called

View File

@ -360,11 +360,11 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
] ]
def __init__(self, row) -> None: # pylint: disable=super-init-not-called def __init__(self, row) -> None: # pylint: disable=super-init-not-called

View File

@ -479,11 +479,11 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
] ]
def __init__(self, row) -> None: # pylint: disable=super-init-not-called def __init__(self, row) -> None: # pylint: disable=super-init-not-called

View File

@ -469,11 +469,11 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
] ]
def __init__(self, row) -> None: # pylint: disable=super-init-not-called def __init__(self, row) -> None: # pylint: disable=super-init-not-called

View File

@ -593,11 +593,11 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
] ]
def __init__(self, row) -> None: # pylint: disable=super-init-not-called def __init__(self, row) -> None: # pylint: disable=super-init-not-called

View File

@ -529,12 +529,12 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row", "_attr_cache",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
"_attr_cache",
] ]
def __init__( # pylint: disable=super-init-not-called def __init__( # pylint: disable=super-init-not-called

View File

@ -694,12 +694,12 @@ class LazyState(State):
"""A lazy version of core State.""" """A lazy version of core State."""
__slots__ = [ __slots__ = [
"_row", "_attr_cache",
"_attributes", "_attributes",
"_context",
"_last_changed", "_last_changed",
"_last_updated", "_last_updated",
"_context", "_row",
"_attr_cache",
] ]
def __init__( # pylint: disable=super-init-not-called def __init__( # pylint: disable=super-init-not-called