style: resolve Ruff UP038 lint violations

This commit is contained in:
mortysean 2026-10-20 21:01:39 +08:00
parent 774ce244b8
commit 99dff9a825
3 changed files with 4 additions and 4 deletions

View File

@ -645,7 +645,7 @@ class LLMEngine:
>>> # abort the request >>> # abort the request
>>> engine.abort_request(request_id) >>> engine.abort_request(request_id)
""" """
assert isinstance(request_id, (str, dict, set, list, tuple)), f"invalid request_id type: {type(request_id)}" assert isinstance(request_id, str | dict | set | list | tuple), f"invalid request_id type: {type(request_id)}"
request_id = [request_id] if isinstance(request_id, str) else list(request_id) request_id = [request_id] if isinstance(request_id, str) else list(request_id)
seqs = self.scheduler.abort_sequence(request_id) seqs = self.scheduler.abort_sequence(request_id)

View File

@ -61,7 +61,7 @@ def _resolve_images(row: dict[str, Any]) -> tuple[tuple[str, ...], tuple[tuple[i
raw = row.get("image") raw = row.get("image")
if not urls and raw: if not urls and raw:
if isinstance(raw, (bytes, bytearray)): if isinstance(raw, bytes | bytearray):
urls = [_write_cached_image(row, bytes(raw), 0)] urls = [_write_cached_image(row, bytes(raw), 0)]
else: else:
text = str(raw).strip() text = str(raw).strip()
@ -102,7 +102,7 @@ def _has_image(row: dict[str, Any]) -> bool:
img = row.get("image") img = row.get("image")
if img is None: if img is None:
return False return False
if isinstance(img, (bytes, bytearray)): if isinstance(img, bytes | bytearray):
return len(img) > 0 return len(img) > 0
return bool(str(img).strip()) return bool(str(img).strip())

View File

@ -27,7 +27,7 @@ def _normalize_trace_events(trace: dict) -> None:
"""replace all time to Decimal""" """replace all time to Decimal"""
for event in trace.get("traceEvents") or []: for event in trace.get("traceEvents") or []:
for key in ("ts", "dur"): for key in ("ts", "dur"):
if key in event and not isinstance(event[key], Decimal) and isinstance(event[key], (str, float)): if key in event and not isinstance(event[key], Decimal) and isinstance(event[key], str | float):
event[f"_was_str_{key}"] = isinstance(event[key], str) event[f"_was_str_{key}"] = isinstance(event[key], str)
event[key] = _to_decimal(event[key]) event[key] = _to_decimal(event[key])