diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index b2a9f1f9b4f..73c957e6e8b 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -5158,7 +5158,7 @@ def _validate_pki_file( return True -async def async_get_broker_settings( # noqa: C901 +async def async_get_broker_settings( flow: ConfigFlow | OptionsFlow, fields: OrderedDict[Any, Any], entry_config: MappingProxyType[str, Any] | None, @@ -5284,15 +5284,11 @@ async def async_get_broker_settings( # noqa: C901 errors["base"] = error return False - if SET_CA_CERT in validated_user_input: - del validated_user_input[SET_CA_CERT] - if SET_CLIENT_CERT in validated_user_input: - del validated_user_input[SET_CLIENT_CERT] + validated_user_input.pop(SET_CA_CERT, None) + validated_user_input.pop(SET_CLIENT_CERT, None) if validated_user_input.get(CONF_TRANSPORT, TRANSPORT_TCP) == TRANSPORT_TCP: - if CONF_WS_PATH in validated_user_input: - del validated_user_input[CONF_WS_PATH] - if CONF_WS_HEADERS in validated_user_input: - del validated_user_input[CONF_WS_HEADERS] + validated_user_input.pop(CONF_WS_PATH, None) + validated_user_input.pop(CONF_WS_HEADERS, None) return True try: validated_user_input[CONF_WS_HEADERS] = json_loads( diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 956fff363ad..16edb0d099f 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -1416,8 +1416,7 @@ async def async_get_integrations( future.set_result(integration) for domain in results: - if domain in needed: - del needed[domain] + needed.pop(domain, None) # Now the rest use resolve_from_root if needed: diff --git a/pyproject.toml b/pyproject.toml index 34bb2e66738..c993f6c5e20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -735,6 +735,7 @@ select = [ "RUF032", # Decimal() called with float literal argument "RUF033", # __post_init__ method with argument defaults "RUF034", # Useless if-else condition + "RUF051", # Use dict.pop(key, None) instead of if-key-in-dict-del "RUF059", # unused-unpacked-variable "RUF100", # Unused `noqa` directive "RUF101", # noqa directives that use redirected rule codes