Skip to content

Commit 1bf3bfc

Browse files
authored
Enable ruff RUF051 rule and simplify dict key removal (home-assistant#170523)
1 parent 1e8a9de commit 1bf3bfc

3 files changed

Lines changed: 7 additions & 11 deletions

File tree

homeassistant/components/mqtt/config_flow.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,7 @@ def _validate_pki_file(
51585158
return True
51595159

51605160

5161-
async def async_get_broker_settings( # noqa: C901
5161+
async def async_get_broker_settings(
51625162
flow: ConfigFlow | OptionsFlow,
51635163
fields: OrderedDict[Any, Any],
51645164
entry_config: MappingProxyType[str, Any] | None,
@@ -5284,15 +5284,11 @@ async def _async_validate_broker_settings(
52845284
errors["base"] = error
52855285
return False
52865286

5287-
if SET_CA_CERT in validated_user_input:
5288-
del validated_user_input[SET_CA_CERT]
5289-
if SET_CLIENT_CERT in validated_user_input:
5290-
del validated_user_input[SET_CLIENT_CERT]
5287+
validated_user_input.pop(SET_CA_CERT, None)
5288+
validated_user_input.pop(SET_CLIENT_CERT, None)
52915289
if validated_user_input.get(CONF_TRANSPORT, TRANSPORT_TCP) == TRANSPORT_TCP:
5292-
if CONF_WS_PATH in validated_user_input:
5293-
del validated_user_input[CONF_WS_PATH]
5294-
if CONF_WS_HEADERS in validated_user_input:
5295-
del validated_user_input[CONF_WS_HEADERS]
5290+
validated_user_input.pop(CONF_WS_PATH, None)
5291+
validated_user_input.pop(CONF_WS_HEADERS, None)
52965292
return True
52975293
try:
52985294
validated_user_input[CONF_WS_HEADERS] = json_loads(

homeassistant/loader.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,7 @@ async def async_get_integrations(
14161416
future.set_result(integration)
14171417

14181418
for domain in results:
1419-
if domain in needed:
1420-
del needed[domain]
1419+
needed.pop(domain, None)
14211420

14221421
# Now the rest use resolve_from_root
14231422
if needed:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ select = [
735735
"RUF032", # Decimal() called with float literal argument
736736
"RUF033", # __post_init__ method with argument defaults
737737
"RUF034", # Useless if-else condition
738+
"RUF051", # Use dict.pop(key, None) instead of if-key-in-dict-del
738739
"RUF059", # unused-unpacked-variable
739740
"RUF100", # Unused `noqa` directive
740741
"RUF101", # noqa directives that use redirected rule codes

0 commit comments

Comments
 (0)