Replace pylint broad-exception-raised rule with ruff (#123021)

This commit is contained in:
epenet 2024-08-02 12:24:03 +02:00 committed by GitHub
parent 5446dd92a9
commit ad26db7dc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 26 additions and 35 deletions

View file

@ -568,8 +568,7 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]):
self.fritz_hosts.get_mesh_topology
)
):
# pylint: disable-next=broad-exception-raised
raise Exception("Mesh supported but empty topology reported")
raise Exception("Mesh supported but empty topology reported") # noqa: TRY002
except FritzActionError:
self.mesh_role = MeshRoles.SLAVE
# Avoid duplicating device trackers

View file

@ -214,8 +214,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
self._captcha_image = data["captchaImg"]
return self._async_form_auth_captcha(error)
# pylint: disable=broad-exception-raised
raise Exception(data)
raise Exception(data) # noqa: TRY002
except Exception as err: # noqa: BLE001
_LOGGER.error("Error auth user: %s", err)
return self._async_form_auth_user(ERROR_AUTH_USER)

View file

@ -312,6 +312,7 @@ disable = [
"no-else-return", # RET505
"broad-except", # BLE001
"protected-access", # SLF001
"broad-exception-raised", # TRY002
# "no-self-use", # PLR6301 # Optional plugin, not enabled
# Handled by mypy
@ -823,7 +824,6 @@ ignore = [
"PYI024", # Use typing.NamedTuple instead of collections.namedtuple
"RET503",
"RET501",
"TRY002",
"TRY301"
]

View file

@ -59,7 +59,7 @@ def get_suggested(schema, key):
return None
return k.description["suggested_value"]
# Wanted key absent from schema
raise Exception
raise KeyError(f"Key `{key}` is missing from schema")
@pytest.mark.parametrize("platform", ["sensor"])

View file

@ -583,8 +583,7 @@ async def test_exception_from_update_method(
nonlocal run_count
run_count += 1
if run_count == 2:
# pylint: disable-next=broad-exception-raised
raise Exception("Test exception")
raise Exception("Test exception") # noqa: TRY002
return GENERIC_PASSIVE_BLUETOOTH_DATA_UPDATE
coordinator = PassiveBluetoothProcessorCoordinator(
@ -1418,8 +1417,7 @@ async def test_exception_from_coordinator_update_method(
nonlocal run_count
run_count += 1
if run_count == 2:
# pylint: disable-next=broad-exception-raised
raise Exception("Test exception")
raise Exception("Test exception") # noqa: TRY002
return {"test": "data"}
@callback

View file

@ -265,7 +265,7 @@ async def test_platform_setup_with_error(
async def async_get_service(hass, config, discovery_info=None):
"""Return None for an invalid notify service."""
raise Exception("Setup error") # pylint: disable=broad-exception-raised
raise Exception("Setup error") # noqa: TRY002
mock_notify_platform(
hass, tmp_path, "testnotify", async_get_service=async_get_service

View file

@ -181,7 +181,7 @@ async def test_dump_log_object(
def __repr__(self):
if self.fail:
raise Exception("failed") # pylint: disable=broad-exception-raised
raise Exception("failed") # noqa: TRY002
return "<DumpLogDummy success>"
obj1 = DumpLogDummy(False)

View file

@ -48,7 +48,7 @@ class RoonApiMockException(RoonApiMock):
@property
def token(self):
"""Throw exception."""
raise Exception # pylint: disable=broad-exception-raised
raise Exception # noqa: TRY002
class RoonDiscoveryMock:

View file

@ -41,7 +41,7 @@ async def test_platform_setup_with_error(
discovery_info: DiscoveryInfoType | None = None,
) -> Provider:
"""Raise exception during platform setup."""
raise Exception("Setup error") # pylint: disable=broad-exception-raised
raise Exception("Setup error") # noqa: TRY002
mock_stt_platform(hass, tmp_path, "bad_stt", async_get_engine=async_get_engine)

View file

@ -110,7 +110,7 @@ async def test_info_endpoint_register_callback_exc(
"""Test that the info endpoint requires auth."""
async def mock_info(hass):
raise Exception("TEST ERROR") # pylint: disable=broad-exception-raised
raise Exception("TEST ERROR") # noqa: TRY002
async_register_info(hass, "lovelace", mock_info)
assert await async_setup_component(hass, "system_health", {})

View file

@ -36,7 +36,7 @@ async def get_error_log(hass_ws_client):
def _generate_and_log_exception(exception, log):
try:
raise Exception(exception) # pylint: disable=broad-exception-raised
raise Exception(exception) # noqa: TRY002
except Exception:
_LOGGER.exception(log)

View file

@ -1016,7 +1016,7 @@ class MockProviderBoom(MockProvider):
) -> tts.TtsAudioType:
"""Load TTS dat."""
# This should not be called, data should be fetched from cache
raise Exception("Boom!") # pylint: disable=broad-exception-raised
raise Exception("Boom!") # noqa: TRY002
class MockEntityBoom(MockTTSEntity):
@ -1027,7 +1027,7 @@ class MockEntityBoom(MockTTSEntity):
) -> tts.TtsAudioType:
"""Load TTS dat."""
# This should not be called, data should be fetched from cache
raise Exception("Boom!") # pylint: disable=broad-exception-raised
raise Exception("Boom!") # noqa: TRY002
@pytest.mark.parametrize("mock_provider", [MockProviderBoom(DEFAULT_LANG)])

View file

@ -123,7 +123,7 @@ async def test_platform_setup_with_error(
discovery_info: DiscoveryInfoType | None = None,
) -> Provider:
"""Raise exception during platform setup."""
raise Exception("Setup error") # pylint: disable=broad-exception-raised
raise Exception("Setup error") # noqa: TRY002
mock_integration(hass, MockModule(domain="bad_tts"))
mock_platform(hass, "bad_tts.tts", BadPlatform(mock_provider))

View file

@ -188,8 +188,7 @@ async def test_callback_exception_gets_logged(
@callback
def bad_handler(*args):
"""Record calls."""
# pylint: disable-next=broad-exception-raised
raise Exception("This is a bad message callback")
raise Exception("This is a bad message callback") # noqa: TRY002
# wrap in partial to test message logging.
async_dispatcher_connect(hass, "test", partial(bad_handler))
@ -209,8 +208,7 @@ async def test_coro_exception_gets_logged(
async def bad_async_handler(*args):
"""Record calls."""
# pylint: disable-next=broad-exception-raised
raise Exception("This is a bad message in a coro")
raise Exception("This is a bad message in a coro") # noqa: TRY002
# wrap in partial to test message logging.
async_dispatcher_connect(hass, "test", bad_async_handler)

View file

@ -584,7 +584,7 @@ async def test_remove_entry_raises(
async def mock_unload_entry(hass, entry):
"""Mock unload entry function."""
raise Exception("BROKEN") # pylint: disable=broad-exception-raised
raise Exception("BROKEN") # noqa: TRY002
mock_integration(hass, MockModule("comp", async_unload_entry=mock_unload_entry))

View file

@ -424,11 +424,11 @@ async def test_async_get_hass_can_be_called(hass: HomeAssistant) -> None:
try:
if ha.async_get_hass() is hass:
return True
raise Exception # pylint: disable=broad-exception-raised
raise Exception # noqa: TRY002
except HomeAssistantError:
return False
raise Exception # pylint: disable=broad-exception-raised
raise Exception # noqa: TRY002
# Test scheduling a coroutine which calls async_get_hass via hass.async_create_task
async def _async_create_task() -> None:

View file

@ -105,7 +105,7 @@ def test_run_does_not_block_forever_with_shielded_task(
try:
await asyncio.sleep(2)
except asyncio.CancelledError:
raise Exception # pylint: disable=broad-exception-raised
raise Exception # noqa: TRY002
async def async_shielded(*_):
try:
@ -142,8 +142,7 @@ async def test_unhandled_exception_traceback(
async def _unhandled_exception():
raised.set()
# pylint: disable-next=broad-exception-raised
raise Exception("This is unhandled")
raise Exception("This is unhandled") # noqa: TRY002
try:
hass.loop.set_debug(True)

View file

@ -338,7 +338,7 @@ async def test_component_exception_setup(hass: HomeAssistant) -> None:
def exception_setup(hass, config):
"""Raise exception."""
raise Exception("fail!") # pylint: disable=broad-exception-raised
raise Exception("fail!") # noqa: TRY002
mock_integration(hass, MockModule("comp", setup=exception_setup))
@ -352,7 +352,7 @@ async def test_component_base_exception_setup(hass: HomeAssistant) -> None:
def exception_setup(hass, config):
"""Raise exception."""
raise BaseException("fail!") # pylint: disable=broad-exception-raised
raise BaseException("fail!") # noqa: TRY002
mock_integration(hass, MockModule("comp", setup=exception_setup))
@ -372,8 +372,7 @@ async def test_component_setup_with_validation_and_dependency(
"""Test that config is passed in."""
if config.get("comp_a", {}).get("valid", False):
return True
# pylint: disable-next=broad-exception-raised
raise Exception(f"Config not passed in: {config}")
raise Exception(f"Config not passed in: {config}") # noqa: TRY002
platform = MockPlatform()

View file

@ -80,8 +80,7 @@ async def test_async_create_catching_coro(
"""Test exception logging of wrapped coroutine."""
async def job():
# pylint: disable-next=broad-exception-raised
raise Exception("This is a bad coroutine")
raise Exception("This is a bad coroutine") # noqa: TRY002
hass.async_create_task(logging_util.async_create_catching_coro(job()))
await hass.async_block_till_done()