diff --git a/pyproject.toml b/pyproject.toml index 80381b09825..1e3e4c86372 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -304,6 +304,10 @@ disable = [ "use-list-literal", # C405 "useless-object-inheritance", # UP004 "useless-return", # PLR1711 + "no-else-break", # RET508 + "no-else-continue", # RET507 + "no-else-raise", # RET506 + "no-else-return", # RET505 # "no-self-use", # PLR6301 # Optional plugin, not enabled # Handled by mypy @@ -633,6 +637,7 @@ select = [ "PIE", # flake8-pie "PL", # pylint "PT", # flake8-pytest-style + "RET", # flake8-return "RSE", # flake8-raise "RUF005", # Consider iterable unpacking instead of concatenation "RUF006", # Store a reference to the return value of asyncio.create_task @@ -713,6 +718,10 @@ ignore = [ # temporarily disabled "PT019", + "RET504", + "RET503", + "RET502", + "RET501", "TRY002", "TRY301" ] diff --git a/script/translations/develop.py b/script/translations/develop.py index 14e3c320c3e..00465e1bc24 100644 --- a/script/translations/develop.py +++ b/script/translations/develop.py @@ -43,7 +43,7 @@ def flatten_translations(translations): if isinstance(v, dict): stack.append(iter(v.items())) break - elif isinstance(v, str): + if isinstance(v, str): common_key = "::".join(key_stack) flattened_translations[common_key] = v key_stack.pop() diff --git a/tests/components/hlk_sw16/test_config_flow.py b/tests/components/hlk_sw16/test_config_flow.py index e4770343114..e8c0d36c81c 100644 --- a/tests/components/hlk_sw16/test_config_flow.py +++ b/tests/components/hlk_sw16/test_config_flow.py @@ -32,9 +32,8 @@ class MockSW16Client: if self.disconnect_callback: self.disconnect_callback() return await self.active_transaction - else: - self.active_transaction.set_result(True) - return self.active_transaction + self.active_transaction.set_result(True) + return self.active_transaction def stop(self): """Mock client stop.""" diff --git a/tests/components/homeassistant/test_exposed_entities.py b/tests/components/homeassistant/test_exposed_entities.py index e20fcb69d00..9a14198b1ef 100644 --- a/tests/components/homeassistant/test_exposed_entities.py +++ b/tests/components/homeassistant/test_exposed_entities.py @@ -32,10 +32,9 @@ def entities_fixture( """Set up the test environment.""" if request.param == "entities_unique_id": return entities_unique_id(entity_registry) - elif request.param == "entities_no_unique_id": + if request.param == "entities_no_unique_id": return entities_no_unique_id(hass) - else: - raise RuntimeError("Invalid setup fixture") + raise RuntimeError("Invalid setup fixture") def entities_unique_id(entity_registry: er.EntityRegistry) -> dict[str, str]: diff --git a/tests/components/kodi/util.py b/tests/components/kodi/util.py index dba0822b1d8..6217a77903b 100644 --- a/tests/components/kodi/util.py +++ b/tests/components/kodi/util.py @@ -57,8 +57,7 @@ def get_kodi_connection( """Get Kodi connection.""" if ws_port is None: return MockConnection() - else: - return MockWSConnection() + return MockWSConnection() class MockConnection: diff --git a/tests/components/matrix/conftest.py b/tests/components/matrix/conftest.py index b3fefe3ac67..2c24f4d0e75 100644 --- a/tests/components/matrix/conftest.py +++ b/tests/components/matrix/conftest.py @@ -84,14 +84,12 @@ class _MockAsyncClient(AsyncClient): return RoomResolveAliasResponse( room_alias=room_alias, room_id=room_id, servers=[TEST_HOMESERVER] ) - else: - return RoomResolveAliasError(message=f"Could not resolve {room_alias}") + return RoomResolveAliasError(message=f"Could not resolve {room_alias}") async def join(self, room_id: RoomID): if room_id in TEST_JOINABLE_ROOMS.values(): return JoinResponse(room_id=room_id) - else: - return JoinError(message="Not allowed to join this room.") + return JoinError(message="Not allowed to join this room.") async def login(self, *args, **kwargs): if kwargs.get("password") == TEST_PASSWORD or kwargs.get("token") == TEST_TOKEN: @@ -101,9 +99,8 @@ class _MockAsyncClient(AsyncClient): device_id="test_device", user_id=TEST_MXID, ) - else: - self.access_token = "" - return LoginError(message="LoginError", status_code="status_code") + self.access_token = "" + return LoginError(message="LoginError", status_code="status_code") async def logout(self, *args, **kwargs): self.access_token = "" @@ -115,19 +112,17 @@ class _MockAsyncClient(AsyncClient): return WhoamiResponse( user_id=TEST_MXID, device_id=TEST_DEVICE_ID, is_guest=False ) - else: - self.access_token = "" - return WhoamiError( - message="Invalid access token passed.", status_code="M_UNKNOWN_TOKEN" - ) + self.access_token = "" + return WhoamiError( + message="Invalid access token passed.", status_code="M_UNKNOWN_TOKEN" + ) async def room_send(self, *args, **kwargs): if not self.logged_in: raise LocalProtocolError if kwargs["room_id"] not in TEST_JOINABLE_ROOMS.values(): return ErrorResponse(message="Cannot send a message in this room.") - else: - return Response() + return Response() async def sync(self, *args, **kwargs): return None diff --git a/tests/components/rflink/test_init.py b/tests/components/rflink/test_init.py index 67f6aa5e6f6..8f09c4a2e54 100644 --- a/tests/components/rflink/test_init.py +++ b/tests/components/rflink/test_init.py @@ -57,8 +57,7 @@ async def mock_rflink( if fail: raise ConnectionRefusedError - else: - return transport, protocol + return transport, protocol mock_create = Mock(wraps=create_rflink_connection) monkeypatch.setattr( diff --git a/tests/components/vesync/common.py b/tests/components/vesync/common.py index 23c57177ddd..94e1511ce19 100644 --- a/tests/components/vesync/common.py +++ b/tests/components/vesync/common.py @@ -75,22 +75,21 @@ def call_api_side_effect__no_devices(*args, **kwargs): """Build a side_effects method for the Helpers.call_api method.""" if args[0] == "/cloud/v1/user/login" and args[1] == "post": return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200 - elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": + if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": return ( json.loads( load_fixture("vesync_api_call__devices__no_devices.json", "vesync") ), 200, ) - else: - raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") + raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") def call_api_side_effect__single_humidifier(*args, **kwargs): """Build a side_effects method for the Helpers.call_api method.""" if args[0] == "/cloud/v1/user/login" and args[1] == "post": return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200 - elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": + if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": return ( json.loads( load_fixture( @@ -99,7 +98,7 @@ def call_api_side_effect__single_humidifier(*args, **kwargs): ), 200, ) - elif args[0] == "/cloud/v2/deviceManaged/bypassV2" and kwargs["method"] == "post": + if args[0] == "/cloud/v2/deviceManaged/bypassV2" and kwargs["method"] == "post": return ( json.loads( load_fixture( @@ -108,22 +107,21 @@ def call_api_side_effect__single_humidifier(*args, **kwargs): ), 200, ) - else: - raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") + raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") def call_api_side_effect__single_fan(*args, **kwargs): """Build a side_effects method for the Helpers.call_api method.""" if args[0] == "/cloud/v1/user/login" and args[1] == "post": return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200 - elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": + if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post": return ( json.loads( load_fixture("vesync_api_call__devices__single_fan.json", "vesync") ), 200, ) - elif ( + if ( args[0] == "/131airPurifier/v1/device/deviceDetail" and kwargs["method"] == "post" ): @@ -135,5 +133,4 @@ def call_api_side_effect__single_fan(*args, **kwargs): ), 200, ) - else: - raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") + raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}") diff --git a/tests/components/zha/common.py b/tests/components/zha/common.py index 63d3e9cf747..6cda8b98e1e 100644 --- a/tests/components/zha/common.py +++ b/tests/components/zha/common.py @@ -244,10 +244,7 @@ def patch_zha_config(component: str, overrides: dict[tuple[str, str], Any]): def new_get_config(config_entry, section, config_key, default): if (section, config_key) in overrides: return overrides[section, config_key] - else: - return async_get_zha_config_value( - config_entry, section, config_key, default - ) + return async_get_zha_config_value(config_entry, section, config_key, default) return patch( f"homeassistant.components.zha.{component}.async_get_zha_config_value", diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index c8c6b21951d..edba232eb69 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -269,8 +269,7 @@ async def test_finish_callback_change_result_type(hass: HomeAssistant) -> None: return flow.async_show_form( step_id="init", data_schema=vol.Schema({"count": int}) ) - else: - result["result"] = result["data"]["count"] + result["result"] = result["data"]["count"] return result manager = FlowManager(hass)