From 9f7a38f189027bc4d495a0ce127c41519ed4930a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 16 Jan 2025 13:48:24 +0100 Subject: [PATCH] Enable RUF022 (#135767) --- homeassistant/auth/permissions/__init__.py | 8 ++--- .../application_credentials/__init__.py | 2 +- .../components/assist_pipeline/__init__.py | 24 ++++++------- .../components/assist_satellite/__init__.py | 2 +- homeassistant/components/backup/__init__.py | 2 +- .../components/bluetooth/__init__.py | 36 +++++++++---------- homeassistant/components/event/__init__.py | 2 +- homeassistant/components/intent/__init__.py | 8 ++--- .../components/media_source/__init__.py | 20 +++++------ homeassistant/components/mqtt/__init__.py | 6 ++-- homeassistant/components/number/__init__.py | 2 +- homeassistant/components/ollama/__init__.py | 10 +++--- homeassistant/components/repairs/__init__.py | 4 +-- homeassistant/components/select/__init__.py | 6 ++-- homeassistant/components/sensor/__init__.py | 2 +- homeassistant/components/spotify/__init__.py | 4 +-- homeassistant/components/stream/__init__.py | 2 +- homeassistant/components/stt/__init__.py | 10 +++--- homeassistant/components/tts/__init__.py | 26 +++++++------- homeassistant/components/update/__init__.py | 2 +- homeassistant/components/usb/__init__.py | 2 +- homeassistant/components/voip/__init__.py | 2 +- .../components/wake_word/__init__.py | 6 ++-- homeassistant/util/ulid.py | 12 +++---- homeassistant/util/yaml/__init__.py | 10 +++--- pyproject.toml | 1 + tests/components/bluetooth/__init__.py | 8 ++--- 27 files changed, 110 insertions(+), 109 deletions(-) diff --git a/homeassistant/auth/permissions/__init__.py b/homeassistant/auth/permissions/__init__.py index 9c2c7e500ca..6498483a19a 100644 --- a/homeassistant/auth/permissions/__init__.py +++ b/homeassistant/auth/permissions/__init__.py @@ -17,12 +17,12 @@ POLICY_SCHEMA = vol.Schema({vol.Optional(CAT_ENTITIES): ENTITY_POLICY_SCHEMA}) __all__ = [ "POLICY_SCHEMA", - "merge_policies", - "PermissionLookup", - "PolicyType", "AbstractPermissions", - "PolicyPermissions", "OwnerPermissions", + "PermissionLookup", + "PolicyPermissions", + "PolicyType", + "merge_policies", ] diff --git a/homeassistant/components/application_credentials/__init__.py b/homeassistant/components/application_credentials/__init__.py index 50b272cc1fa..58146818624 100644 --- a/homeassistant/components/application_credentials/__init__.py +++ b/homeassistant/components/application_credentials/__init__.py @@ -38,7 +38,7 @@ from homeassistant.loader import ( from homeassistant.util import slugify from homeassistant.util.hass_dict import HassKey -__all__ = ["ClientCredential", "AuthorizationServer", "async_import_client_credential"] +__all__ = ["AuthorizationServer", "ClientCredential", "async_import_client_credential"] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/assist_pipeline/__init__.py b/homeassistant/components/assist_pipeline/__init__.py index 851c873bb12..cc7ecc1c426 100644 --- a/homeassistant/components/assist_pipeline/__init__.py +++ b/homeassistant/components/assist_pipeline/__init__.py @@ -46,24 +46,24 @@ from .websocket_api import async_register_websocket_api __all__ = ( "DOMAIN", - "async_create_default_pipeline", - "async_get_pipelines", - "async_migrate_engine", - "async_setup", - "async_pipeline_from_audio_stream", - "async_update_pipeline", + "EVENT_RECORDING", + "OPTION_PREFERRED", + "SAMPLES_PER_CHUNK", + "SAMPLE_CHANNELS", + "SAMPLE_RATE", + "SAMPLE_WIDTH", "AudioSettings", "Pipeline", "PipelineEvent", "PipelineEventType", "PipelineNotFound", "WakeWordSettings", - "EVENT_RECORDING", - "OPTION_PREFERRED", - "SAMPLES_PER_CHUNK", - "SAMPLE_RATE", - "SAMPLE_WIDTH", - "SAMPLE_CHANNELS", + "async_create_default_pipeline", + "async_get_pipelines", + "async_migrate_engine", + "async_pipeline_from_audio_stream", + "async_setup", + "async_update_pipeline", ) CONFIG_SCHEMA = vol.Schema( diff --git a/homeassistant/components/assist_satellite/__init__.py b/homeassistant/components/assist_satellite/__init__.py index dd940e8cdbe..47b0123a244 100644 --- a/homeassistant/components/assist_satellite/__init__.py +++ b/homeassistant/components/assist_satellite/__init__.py @@ -30,8 +30,8 @@ from .websocket_api import async_register_websocket_api __all__ = [ "DOMAIN", "AssistSatelliteAnnouncement", - "AssistSatelliteEntity", "AssistSatelliteConfiguration", + "AssistSatelliteEntity", "AssistSatelliteEntityDescription", "AssistSatelliteEntityFeature", "AssistSatelliteWakeWord", diff --git a/homeassistant/components/backup/__init__.py b/homeassistant/components/backup/__init__.py index 00b226a9fee..f3fe2246ad1 100644 --- a/homeassistant/components/backup/__init__.py +++ b/homeassistant/components/backup/__init__.py @@ -35,7 +35,6 @@ from .websocket import async_register_websocket_handlers __all__ = [ "AddonInfo", "AgentBackup", - "ManagerBackup", "BackupAgent", "BackupAgentError", "BackupAgentPlatformProtocol", @@ -46,6 +45,7 @@ __all__ = [ "Folder", "IncorrectPasswordError", "LocalBackupAgent", + "ManagerBackup", "NewBackup", "WrittenBackup", ] diff --git a/homeassistant/components/bluetooth/__init__.py b/homeassistant/components/bluetooth/__init__.py index ef89bef7ca1..8da4e9c61e0 100644 --- a/homeassistant/components/bluetooth/__init__.py +++ b/homeassistant/components/bluetooth/__init__.py @@ -93,9 +93,24 @@ if TYPE_CHECKING: from homeassistant.helpers.typing import ConfigType __all__ = [ + "FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS", + "MONOTONIC_TIME", + "SOURCE_LOCAL", + "BaseHaRemoteScanner", + "BaseHaScanner", + "BluetoothCallback", + "BluetoothCallbackMatcher", + "BluetoothChange", + "BluetoothScannerDevice", + "BluetoothScanningMode", + "BluetoothServiceInfo", + "BluetoothServiceInfoBleak", + "HaBluetoothConnector", + "HomeAssistantRemoteScanner", "async_address_present", "async_ble_device_from_address", "async_discovered_service_info", + "async_get_advertisement_callback", "async_get_fallback_availability_interval", "async_get_learned_advertising_interval", "async_get_scanner", @@ -104,27 +119,12 @@ __all__ = [ "async_rediscover_address", "async_register_callback", "async_register_scanner", - "async_set_fallback_availability_interval", - "async_track_unavailable", + "async_remove_scanner", "async_scanner_by_source", "async_scanner_count", "async_scanner_devices_by_address", - "async_get_advertisement_callback", - "async_remove_scanner", - "BaseHaScanner", - "HomeAssistantRemoteScanner", - "BluetoothCallbackMatcher", - "BluetoothChange", - "BluetoothServiceInfo", - "BluetoothServiceInfoBleak", - "BluetoothScanningMode", - "BluetoothCallback", - "BluetoothScannerDevice", - "HaBluetoothConnector", - "BaseHaRemoteScanner", - "SOURCE_LOCAL", - "FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS", - "MONOTONIC_TIME", + "async_set_fallback_availability_interval", + "async_track_unavailable", ] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/event/__init__.py b/homeassistant/components/event/__init__.py index c4a8fb2d0af..5bdf107f0c3 100644 --- a/homeassistant/components/event/__init__.py +++ b/homeassistant/components/event/__init__.py @@ -42,8 +42,8 @@ __all__ = [ "ATTR_EVENT_TYPE", "ATTR_EVENT_TYPES", "DOMAIN", - "PLATFORM_SCHEMA_BASE", "PLATFORM_SCHEMA", + "PLATFORM_SCHEMA_BASE", "EventDeviceClass", "EventEntity", "EventEntityDescription", diff --git a/homeassistant/components/intent/__init__.py b/homeassistant/components/intent/__init__.py index 71ef40ad369..a1451f8fcca 100644 --- a/homeassistant/components/intent/__init__.py +++ b/homeassistant/components/intent/__init__.py @@ -65,11 +65,11 @@ _LOGGER = logging.getLogger(__name__) CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) __all__ = [ - "async_register_timer_handler", - "async_device_supports_timers", - "TimerInfo", - "TimerEventType", "DOMAIN", + "TimerEventType", + "TimerInfo", + "async_device_supports_timers", + "async_register_timer_handler", ] ONOFF_DEVICE_CLASSES = { diff --git a/homeassistant/components/media_source/__init__.py b/homeassistant/components/media_source/__init__.py index 3ea8f581245..5c6165a3477 100644 --- a/homeassistant/components/media_source/__init__.py +++ b/homeassistant/components/media_source/__init__.py @@ -38,18 +38,18 @@ from .models import BrowseMediaSource, MediaSource, MediaSourceItem, PlayMedia __all__ = [ "DOMAIN", - "is_media_source_id", - "generate_media_source_id", - "async_browse_media", - "async_resolve_media", - "BrowseMediaSource", - "PlayMedia", - "MediaSourceItem", - "Unresolvable", - "MediaSource", - "MediaSourceError", "MEDIA_CLASS_MAP", "MEDIA_MIME_TYPES", + "BrowseMediaSource", + "MediaSource", + "MediaSourceError", + "MediaSourceItem", + "PlayMedia", + "Unresolvable", + "async_browse_media", + "async_resolve_media", + "generate_media_source_id", + "is_media_source_id", ] diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index b494b636916..8b16e9fa53d 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -143,21 +143,21 @@ __all__ = [ "DOMAIN", "ENTITY_PLATFORMS", "ENTRY_OPTION_FIELDS", - "EntitySubscription", "MQTT", "MQTT_BASE_SCHEMA", "MQTT_CONNECTION_STATE", "MQTT_RO_SCHEMA", "MQTT_RW_SCHEMA", + "SERVICE_RELOAD", + "TEMPLATE_ERRORS", + "EntitySubscription", "MqttCommandTemplate", "MqttData", "MqttValueTemplate", "PayloadSentinel", "PublishPayloadType", "ReceiveMessage", - "SERVICE_RELOAD", "SetupPhases", - "TEMPLATE_ERRORS", "async_check_config_schema", "async_create_certificate_temp_files", "async_forward_entry_setup_and_setup_discovery", diff --git a/homeassistant/components/number/__init__.py b/homeassistant/components/number/__init__.py index 9f4aef08aa9..2f5ebcdb44c 100644 --- a/homeassistant/components/number/__init__.py +++ b/homeassistant/components/number/__init__.py @@ -68,8 +68,8 @@ __all__ = [ "DEFAULT_MIN_VALUE", "DEFAULT_STEP", "DOMAIN", - "PLATFORM_SCHEMA_BASE", "PLATFORM_SCHEMA", + "PLATFORM_SCHEMA_BASE", "NumberDeviceClass", "NumberEntity", "NumberEntityDescription", diff --git a/homeassistant/components/ollama/__init__.py b/homeassistant/components/ollama/__init__.py index 3bcba567803..6983db73cf4 100644 --- a/homeassistant/components/ollama/__init__.py +++ b/homeassistant/components/ollama/__init__.py @@ -28,12 +28,12 @@ from .const import ( _LOGGER = logging.getLogger(__name__) __all__ = [ - "CONF_URL", - "CONF_PROMPT", - "CONF_MODEL", - "CONF_MAX_HISTORY", - "CONF_NUM_CTX", "CONF_KEEP_ALIVE", + "CONF_MAX_HISTORY", + "CONF_MODEL", + "CONF_NUM_CTX", + "CONF_PROMPT", + "CONF_URL", "DOMAIN", ] diff --git a/homeassistant/components/repairs/__init__.py b/homeassistant/components/repairs/__init__.py index 8d3fc429ce0..8ee09c9ed3d 100644 --- a/homeassistant/components/repairs/__init__.py +++ b/homeassistant/components/repairs/__init__.py @@ -12,11 +12,11 @@ from .issue_handler import ConfirmRepairFlow, RepairsFlowManager from .models import RepairsFlow __all__ = [ - "ConfirmRepairFlow", "DOMAIN", - "repairs_flow_manager", + "ConfirmRepairFlow", "RepairsFlow", "RepairsFlowManager", + "repairs_flow_manager", ] CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) diff --git a/homeassistant/components/select/__init__.py b/homeassistant/components/select/__init__.py index 3834dc4a0c7..592b746198e 100644 --- a/homeassistant/components/select/__init__.py +++ b/homeassistant/components/select/__init__.py @@ -45,15 +45,15 @@ __all__ = [ "ATTR_OPTION", "ATTR_OPTIONS", "DOMAIN", - "PLATFORM_SCHEMA_BASE", "PLATFORM_SCHEMA", - "SelectEntity", - "SelectEntityDescription", + "PLATFORM_SCHEMA_BASE", "SERVICE_SELECT_FIRST", "SERVICE_SELECT_LAST", "SERVICE_SELECT_NEXT", "SERVICE_SELECT_OPTION", "SERVICE_SELECT_PREVIOUS", + "SelectEntity", + "SelectEntityDescription", ] # mypy: disallow-any-generics diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 2933d779b4b..37df50b2099 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -67,8 +67,8 @@ __all__ = [ "CONF_STATE_CLASS", "DEVICE_CLASS_STATE_CLASSES", "DOMAIN", - "PLATFORM_SCHEMA_BASE", "PLATFORM_SCHEMA", + "PLATFORM_SCHEMA_BASE", "RestoreSensor", "SensorDeviceClass", "SensorEntity", diff --git a/homeassistant/components/spotify/__init__.py b/homeassistant/components/spotify/__init__.py index 37580ac432d..663b3f30caa 100644 --- a/homeassistant/components/spotify/__init__.py +++ b/homeassistant/components/spotify/__init__.py @@ -32,11 +32,11 @@ from .util import ( PLATFORMS = [Platform.MEDIA_PLAYER] __all__ = [ - "async_browse_media", "DOMAIN", - "spotify_uri_from_media_browser_url", + "async_browse_media", "is_spotify_media_type", "resolve_spotify_media_type", + "spotify_uri_from_media_browser_url", ] diff --git a/homeassistant/components/stream/__init__.py b/homeassistant/components/stream/__init__.py index 8692a2acaad..2772fc2d30e 100644 --- a/homeassistant/components/stream/__init__.py +++ b/homeassistant/components/stream/__init__.py @@ -90,11 +90,11 @@ __all__ = [ "OUTPUT_FORMATS", "RTSP_TRANSPORTS", "SOURCE_TIMEOUT", + "Orientation", "Stream", "StreamClientError", "StreamOpenClientError", "create_stream", - "Orientation", ] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/stt/__init__.py b/homeassistant/components/stt/__init__.py index d3c85aba1e7..25ed29d3071 100644 --- a/homeassistant/components/stt/__init__.py +++ b/homeassistant/components/stt/__init__.py @@ -49,20 +49,20 @@ from .legacy import ( from .models import SpeechMetadata, SpeechResult __all__ = [ - "async_get_provider", - "async_get_speech_to_text_engine", - "async_get_speech_to_text_entity", + "DOMAIN", "AudioBitRates", "AudioChannels", "AudioCodecs", "AudioFormats", "AudioSampleRates", - "DOMAIN", "Provider", - "SpeechToTextEntity", "SpeechMetadata", "SpeechResult", "SpeechResultState", + "SpeechToTextEntity", + "async_get_provider", + "async_get_speech_to_text_engine", + "async_get_speech_to_text_entity", ] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index e7d1091719b..80c175ccfe4 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -73,23 +73,23 @@ from .media_source import generate_media_source_id, media_source_id_to_kwargs from .models import Voice __all__ = [ + "ATTR_AUDIO_OUTPUT", + "ATTR_PREFERRED_FORMAT", + "ATTR_PREFERRED_SAMPLE_BYTES", + "ATTR_PREFERRED_SAMPLE_CHANNELS", + "ATTR_PREFERRED_SAMPLE_RATE", + "CONF_LANG", + "DEFAULT_CACHE_DIR", + "PLATFORM_SCHEMA", + "PLATFORM_SCHEMA_BASE", + "Provider", + "SampleFormat", + "TtsAudioType", + "Voice", "async_default_engine", "async_get_media_source_audio", "async_support_options", - "ATTR_AUDIO_OUTPUT", - "ATTR_PREFERRED_FORMAT", - "ATTR_PREFERRED_SAMPLE_RATE", - "ATTR_PREFERRED_SAMPLE_CHANNELS", - "ATTR_PREFERRED_SAMPLE_BYTES", - "CONF_LANG", - "DEFAULT_CACHE_DIR", "generate_media_source_id", - "PLATFORM_SCHEMA_BASE", - "PLATFORM_SCHEMA", - "SampleFormat", - "Provider", - "TtsAudioType", - "Voice", ] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/update/__init__.py b/homeassistant/components/update/__init__.py index 8ef9f44237f..a2ecd494920 100644 --- a/homeassistant/components/update/__init__.py +++ b/homeassistant/components/update/__init__.py @@ -68,8 +68,8 @@ __all__ = [ "ATTR_VERSION", "DEVICE_CLASSES_SCHEMA", "DOMAIN", - "PLATFORM_SCHEMA_BASE", "PLATFORM_SCHEMA", + "PLATFORM_SCHEMA_BASE", "SERVICE_INSTALL", "SERVICE_SKIP", "UpdateDeviceClass", diff --git a/homeassistant/components/usb/__init__.py b/homeassistant/components/usb/__init__.py index 7eaac7d71e8..a4bbe2dcf78 100644 --- a/homeassistant/components/usb/__init__.py +++ b/homeassistant/components/usb/__init__.py @@ -49,9 +49,9 @@ _LOGGER = logging.getLogger(__name__) REQUEST_SCAN_COOLDOWN = 10 # 10 second cooldown __all__ = [ + "USBCallbackMatcher", "async_is_plugged_in", "async_register_scan_request_callback", - "USBCallbackMatcher", ] CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) diff --git a/homeassistant/components/voip/__init__.py b/homeassistant/components/voip/__init__.py index cee0cbb0766..96e758e91f4 100644 --- a/homeassistant/components/voip/__init__.py +++ b/homeassistant/components/voip/__init__.py @@ -30,9 +30,9 @@ _IP_WILDCARD = "0.0.0.0" __all__ = [ "DOMAIN", + "async_remove_config_entry_device", "async_setup_entry", "async_unload_entry", - "async_remove_config_entry_device", ] diff --git a/homeassistant/components/wake_word/__init__.py b/homeassistant/components/wake_word/__init__.py index 8b3a5bbf331..65556668bac 100644 --- a/homeassistant/components/wake_word/__init__.py +++ b/homeassistant/components/wake_word/__init__.py @@ -25,12 +25,12 @@ from .const import DOMAIN from .models import DetectionResult, WakeWord __all__ = [ - "async_default_entity", - "async_get_wake_word_detection_entity", - "DetectionResult", "DOMAIN", + "DetectionResult", "WakeWord", "WakeWordDetectionEntity", + "async_default_entity", + "async_get_wake_word_detection_entity", ] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/util/ulid.py b/homeassistant/util/ulid.py index f4895f9d963..ba0c466969c 100644 --- a/homeassistant/util/ulid.py +++ b/homeassistant/util/ulid.py @@ -13,14 +13,14 @@ from ulid_transform import ( ) __all__ = [ - "ulid", - "ulid_hex", - "ulid_at_time", - "ulid_to_bytes", "bytes_to_ulid", - "ulid_now", - "ulid_to_bytes_or_none", "bytes_to_ulid_or_none", + "ulid", + "ulid_at_time", + "ulid_hex", + "ulid_now", + "ulid_to_bytes", + "ulid_to_bytes_or_none", ] diff --git a/homeassistant/util/yaml/__init__.py b/homeassistant/util/yaml/__init__.py index cf90b223cb6..3b1f5c4cc0a 100644 --- a/homeassistant/util/yaml/__init__.py +++ b/homeassistant/util/yaml/__init__.py @@ -16,15 +16,15 @@ from .objects import Input __all__ = [ "SECRET_YAML", "Input", - "dump", - "save_yaml", "Secrets", + "UndefinedSubstitution", "YamlTypeError", + "dump", + "extract_inputs", "load_yaml", "load_yaml_dict", - "secret_yaml", "parse_yaml", - "UndefinedSubstitution", - "extract_inputs", + "save_yaml", + "secret_yaml", "substitute", ] diff --git a/pyproject.toml b/pyproject.toml index 406fbe6cf25..26224fc3b63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -759,6 +759,7 @@ select = [ "RUF017", # Avoid quadratic list summation "RUF018", # Avoid assignment expressions in assert statements "RUF019", # Unnecessary key check before dictionary access + "RUF022", # Sort __all__ "RUF100", # Unused `noqa` directive "S102", # Use of exec detected "S103", # bad-file-permissions diff --git a/tests/components/bluetooth/__init__.py b/tests/components/bluetooth/__init__.py index 8794d808718..a9213de34ff 100644 --- a/tests/components/bluetooth/__init__.py +++ b/tests/components/bluetooth/__init__.py @@ -25,17 +25,17 @@ from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry __all__ = ( + "MockBleakClient", + "generate_advertisement_data", + "generate_ble_device", "inject_advertisement", "inject_advertisement_with_source", "inject_advertisement_with_time_and_source", "inject_advertisement_with_time_and_source_connectable", "inject_bluetooth_service_info", "patch_all_discovered_devices", - "patch_discovered_devices", - "generate_advertisement_data", - "generate_ble_device", - "MockBleakClient", "patch_bluetooth_time", + "patch_discovered_devices", ) ADVERTISEMENT_DATA_DEFAULTS = {