Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pylint broad-except with Ruff BLE001 #116250

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion homeassistant/components/airnow/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def async_step_user(
errors["base"] = "invalid_auth"
except InvalidLocation:
errors["base"] = "invalid_location"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/airthings/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def async_step_user(
errors["base"] = "cannot_connect"
except airthings.AirthingsAuthError:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/airthings_ble/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def async_step_bluetooth(
device = await self._get_device_data(discovery_info)
except AirthingsDeviceUpdateError:
return self.async_abort(reason="cannot_connect")
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
return self.async_abort(reason="unknown")

name = get_name(device)
Expand Down Expand Up @@ -160,7 +160,7 @@ async def async_step_user(
device = await self._get_device_data(discovery_info)
except AirthingsDeviceUpdateError:
return self.async_abort(reason="cannot_connect")
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
return self.async_abort(reason="unknown")
name = get_name(device)
self._discovered_devices[address] = Discovery(name, discovery_info, device)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/airtouch5/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def async_step_user(
client = Airtouch5SimpleClient(user_input[CONF_HOST])
try:
await client.test_connection()
except Exception: # pylint: disable=broad-exception-caught
except Exception: # noqa: BLE001
errors = {"base": "cannot_connect"}
else:
await self.async_set_unique_id(user_input[CONF_HOST])
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/airvisual_pro/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def async_validate_credentials(
except NodeProError as err:
LOGGER.error("Unknown Pro error while connecting to %s: %s", ip_address, err)
errors["base"] = "unknown"
except Exception as err: # pylint: disable=broad-except
except Exception as err: # noqa: BLE001
thecode marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.exception("Unknown error while connecting to %s: %s", ip_address, err)
errors["base"] = "unknown"
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/alarmdecoder/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_connection():
)
except NoDeviceError:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception during AlarmDecoder setup")
errors["base"] = "unknown"

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/alexa/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def serialize_properties(self) -> Generator[dict[str, Any], None, None]:
prop_value = self.get_property(prop_name)
except UnsupportedProperty:
raise
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Unexpected error getting %s.%s property from %s",
self.name(),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/alexa/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def serialize_discovery(self) -> dict[str, Any]:

try:
capabilities.append(i.serialize_discovery())
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Error serializing %s discovery for %s", i.name(), self.entity
)
Expand All @@ -379,7 +379,7 @@ def async_get_entities(
try:
alexa_entity = ENTITY_ADAPTERS[state.domain](hass, config, state)
interfaces = list(alexa_entity.interfaces())
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unable to serialize %s for discovery", state.entity_id)
else:
if not interfaces:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/alexa/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def async_api_discovery(
continue
try:
discovered_serialized_entity = alexa_entity.serialize_discovery()
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Unable to serialize %s for discovery", alexa_entity.entity_id
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/alexa/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def async_handle_message(
error_message=err.error_message,
payload=err.payload,
)
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Uncaught exception processing Alexa %s/%s request (%s)",
directive.namespace,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/androidtv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def _async_check_connection(

try:
aftv, error_message = await async_connect_androidtv(self.hass, user_input)
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Unknown error connecting with Android device at %s",
user_input[CONF_HOST],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/androidtv/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def _adb_exception_catcher(
await self.aftv.adb_close()
self._attr_available = False
return None
except Exception as err: # pylint: disable=broad-except
except Exception as err: # noqa: BLE001
# An unforeseen exception occurred. Close the ADB connection so that
# it doesn't happen over and over again.
if self.available:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/anova/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def async_step_user(
errors["base"] = "invalid_auth"
except NoDevicesFound:
errors["base"] = "no_devices_found"
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
errors["base"] = "unknown"
else:
# We store device list in config flow in order to persist found devices on restart, as the Anova api get_devices does not return any devices that are offline.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/aosmith/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def _async_validate_credentials(
await client.get_devices()
except AOSmithInvalidCredentialsException:
return "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
return "unknown"

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/apple_tv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def disconnect(self) -> None:
if self._task:
self._task.cancel()
self._task = None
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("An error occurred while disconnecting")

def _start_connect_loop(self) -> None:
Expand Down Expand Up @@ -292,7 +292,7 @@ async def connect_once(self, raise_missing_credentials: bool) -> None:
return
except asyncio.CancelledError:
pass
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Failed to connect")
await self.disconnect()

Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/apple_tv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async def async_step_user(
errors["base"] = "no_devices_found"
except DeviceAlreadyConfigured:
errors["base"] = "already_configured"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down Expand Up @@ -329,7 +329,7 @@ async def async_find_device_wrapper(
return self.async_abort(reason="no_devices_found")
except DeviceAlreadyConfigured:
return self.async_abort(reason="already_configured")
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
return self.async_abort(reason="unknown")

Expand Down Expand Up @@ -472,7 +472,7 @@ async def async_pair_next_protocol(self) -> ConfigFlowResult:
except exceptions.PairingError:
_LOGGER.exception("Authentication problem")
abort_reason = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
abort_reason = "unknown"

Expand Down Expand Up @@ -514,7 +514,7 @@ async def async_step_pair_with_pin(
except exceptions.PairingError:
_LOGGER.exception("Authentication problem")
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/arcam_fmj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ def _listen(_: Any) -> None:
await asyncio.sleep(interval)
except TimeoutError:
continue
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception, aborting arcam client")
return
4 changes: 2 additions & 2 deletions homeassistant/components/aseko_pool_live/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def async_step_user(
errors["base"] = "cannot_connect"
except InvalidAuthCredentials:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down Expand Up @@ -126,7 +126,7 @@ async def async_step_reauth_confirm(
errors["base"] = "cannot_connect"
except InvalidAuthCredentials:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ def _pipeline_debug_recording_thread_proc(
wav_writer.writeframes(message)
except Empty:
pass # occurs when pipeline has unexpected error
except Exception: # pylint: disable=broad-exception-caught
except Exception:
_LOGGER.exception("Unexpected error in debug recording thread")
finally:
if wav_writer is not None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/asuswrt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async def _async_check_connection(
)
error = RESULT_CONN_ERROR

except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Unknown error connecting with AsusWrt router at %s using protocol %s",
host,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/august/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def _async_auth_or_validate(self) -> ValidateResult:
errors["base"] = "invalid_auth"
except RequireValidation:
validation_required = True
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unhandled"
description_placeholders = {"error": str(ex)}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/aurora/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def async_step_user(
await api.get_forecast_data(longitude, latitude)
except ClientError:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def websocket_delete_all_refresh_tokens(
continue
try:
hass.auth.async_remove_refresh_token(token)
except Exception: # pylint: disable=broad-except
except Exception:
getLogger(__name__).exception("Error during refresh token removal")
remove_failed = True

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def started_action() -> None:
err,
)
automation_trace.set_error(err)
except Exception as err: # pylint: disable=broad-except
except Exception as err:
self._logger.exception("While executing automation %s", self.entity_id)
automation_trace.set_error(err)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/azure_event_hub/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def validate_data(data: dict[str, Any]) -> dict[str, str] | None:
await client.test_connection()
except EventHubError:
return {"base": "cannot_connect"}
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unknown error")
return {"base": "unknown"}
return None
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/backup/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def handle_backup_start(

try:
await manager.pre_backup_actions()
except Exception as err: # pylint: disable=broad-except
except Exception as err: # noqa: BLE001
connection.send_error(msg["id"], "pre_backup_actions_failed", str(err))
return

Expand All @@ -114,7 +114,7 @@ async def handle_backup_end(

try:
await manager.post_backup_actions()
except Exception as err: # pylint: disable=broad-except
except Exception as err: # noqa: BLE001
connection.send_error(msg["id"], "post_backup_actions_failed", str(err))
return

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/baf/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def async_step_user(
device = await async_try_connect(ip_address)
except CannotConnect:
errors[CONF_IP_ADDRESS] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception(
"Unknown exception during connection test to %s", ip_address
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/balboa/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def async_step_user(
info = await validate_input(user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/blink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def async_step_user(
return await self.async_step_2fa()
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

Expand All @@ -96,7 +96,7 @@ async def async_step_2fa(
)
except BlinkSetupError:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/blue_current/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def async_step_user(
errors["base"] = "already_connected"
except InvalidApiToken:
errors["base"] = "invalid_token"
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def _async_poll(self) -> None:
)
self.last_poll_successful = False
return
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
if self.last_poll_successful:
self.logger.exception("%s: Failure while polling", self.address)
self.last_poll_successful = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def _async_poll(self) -> None:
)
self.last_poll_successful = False
return
except Exception: # pylint: disable=broad-except
except Exception: # noqa: BLE001
if self.last_poll_successful:
self.logger.exception("%s: Failure while polling", self.address)
self.last_poll_successful = False
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/bluetooth/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _discover_service_info(self, service_info: BluetoothServiceInfoBleak) -> Non
callback = match[CALLBACK]
try:
callback(service_info, BluetoothChange.ADVERTISEMENT)
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Error in bluetooth callback")

for domain in matched_domains:
Expand Down Expand Up @@ -182,7 +182,7 @@ def _async_remove_callback() -> None:
if ble_device_matches(callback_matcher, service_info):
try:
callback(service_info, BluetoothChange.ADVERTISEMENT)
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Error in bluetooth callback")

return _async_remove_callback
Expand Down