Skip to content

Commit 223fefb

Browse files
authored
Enable Ruff RUF018 (#115485)
1 parent 1a9ff8c commit 223fefb

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

homeassistant/components/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ async def post(self, request: web.Request, entity_id: str) -> web.Response:
284284

285285
# Read the state back for our response
286286
status_code = HTTPStatus.CREATED if is_new_state else HTTPStatus.OK
287-
assert (state := hass.states.get(entity_id))
287+
state = hass.states.get(entity_id)
288+
assert state
288289
resp = self.json(state.as_dict(), status_code)
289290

290291
resp.headers.add("Location", f"/api/states/{entity_id}")

homeassistant/components/light/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,13 @@ async def async_handle_light_on_service( # noqa: C901
517517
params[ATTR_COLOR_TEMP_KELVIN]
518518
)
519519
elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
520-
assert (rgb_color := params.pop(ATTR_RGB_COLOR)) is not None
520+
rgb_color = params.pop(ATTR_RGB_COLOR)
521+
assert rgb_color is not None
521522
if ColorMode.RGBW in supported_color_modes:
522523
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
523524
elif ColorMode.RGBWW in supported_color_modes:
524-
# https://github.com/python/mypy/issues/13673
525525
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
526-
*rgb_color, # type: ignore[call-arg]
526+
*rgb_color,
527527
light.min_color_temp_kelvin,
528528
light.max_color_temp_kelvin,
529529
)
@@ -584,9 +584,9 @@ async def async_handle_light_on_service( # noqa: C901
584584
elif (
585585
ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
586586
):
587-
assert (rgbww_color := params.pop(ATTR_RGBWW_COLOR)) is not None
588-
# https://github.com/python/mypy/issues/13673
589-
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
587+
rgbww_color = params.pop(ATTR_RGBWW_COLOR)
588+
assert rgbww_color is not None
589+
rgb_color = color_util.color_rgbww_to_rgb(
590590
*rgbww_color, light.min_color_temp_kelvin, light.max_color_temp_kelvin
591591
)
592592
if ColorMode.RGB in supported_color_modes:

homeassistant/components/mqtt_statestream/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
5757

5858
async def _state_publisher(evt: Event[EventStateChangedData]) -> None:
5959
entity_id = evt.data["entity_id"]
60-
assert (new_state := evt.data["new_state"])
60+
new_state = evt.data["new_state"]
61+
assert new_state
6162

6263
payload = new_state.state
6364

homeassistant/components/ring/camera.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ async def async_update(self) -> None:
167167
def _get_video(self) -> str | None:
168168
if self._last_event is None:
169169
return None
170-
assert (event_id := self._last_event.get("id")) and isinstance(event_id, int)
170+
event_id = self._last_event.get("id")
171+
assert event_id and isinstance(event_id, int)
171172
return self._device.recording_url(event_id)
172173

173174
@exception_wrap

homeassistant/components/zwave_js/diagnostics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ async def async_get_device_diagnostics(
151151
client: Client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT]
152152
identifiers = get_home_and_node_id_from_device_entry(device)
153153
node_id = identifiers[1] if identifiers else None
154-
assert (driver := client.driver)
154+
driver = client.driver
155+
assert driver
155156
if node_id is None or node_id not in driver.controller.nodes:
156157
raise ValueError(f"Node for device {device.id} can't be found")
157158
node = driver.controller.nodes[node_id]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ select = [
701701
"RUF005", # Consider iterable unpacking instead of concatenation
702702
"RUF006", # Store a reference to the return value of asyncio.create_task
703703
"RUF013", # PEP 484 prohibits implicit Optional
704+
"RUF018", # Avoid assignment expressions in assert statements
704705
# "RUF100", # Unused `noqa` directive; temporarily every now and then to clean them up
705706
"S102", # Use of exec detected
706707
"S103", # bad-file-permissions

tests/ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extend = "../pyproject.toml"
66
extend-ignore = [
77
"B904", # Use raise from to specify exception cause
88
"N815", # Variable {name} in class scope should not be mixedCase
9+
"RUF018", # Avoid assignment expressions in assert statements
910
]
1011

1112
[lint.isort]

0 commit comments

Comments
 (0)