完成 Ruff 全量清理

This commit is contained in:
yml2213
2026-08-31 10:55:44 +08:00
parent 840af3108e
commit 09ab80e062
68 changed files with 323 additions and 291 deletions
+17 -21
View File
@@ -17,6 +17,7 @@ from __future__ import annotations
import itertools
import json
import math
import random
import urllib.parse
from pathlib import Path
@@ -40,7 +41,7 @@ def _ic(x):
try:
f = float(x)
return 0 if math.isnan(f) else int(f)
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return 0
@@ -79,7 +80,7 @@ def js_typeof(v):
return "number"
if isinstance(v, str):
return "string"
if isinstance(v, JSFunction) or isinstance(v, HostFunction):
if isinstance(v, (JSFunction, HostFunction)):
return "function"
return "object"
@@ -99,7 +100,7 @@ def js_truthy(v):
def _nan_ok(x):
try:
return not (isinstance(x, float) and math.isnan(x))
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return True
@@ -207,7 +208,7 @@ def js_num(v):
return v
try:
return float(v)
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return float("nan")
@@ -226,12 +227,12 @@ def js_eq(a, b):
if isinstance(a, (int, float)) and isinstance(b, str):
try:
return a == float(b)
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
if isinstance(b, (int, float)) and isinstance(a, str):
try:
return float(a) == b
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
return a == b
@@ -355,9 +356,7 @@ def js_set(obj, key, val):
pass
if isinstance(obj, str):
raise TypeError("Cannot assign to read only property")
cur = getattr(
__import__("pyvm.algorithm", fromlist=["x"]).VM, "_last_u", None
)
cur = getattr(__import__("pyvm.algorithm", fromlist=["x"]).VM, "_last_u", None)
raise TypeError(
f"invalid set target obj={type(obj).__name__} key={key!r} val={type(val).__name__} u={cur}"
)
@@ -736,7 +735,7 @@ def h_parsefloat(this, s):
def h_isnan(this, x):
try:
return math.isnan(float(x))
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return True
@@ -896,7 +895,7 @@ class VM:
for x in v:
try:
parts.append("%02x" % (int(x) & 255))
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
parts.append("??")
self.out_hex = "".join(parts)
# 仅供离线排查 webSave 输出缓冲何时变化,生产路径默认不启用。
@@ -1527,9 +1526,7 @@ class VM:
if not (
isinstance(fn, (JSFunction, HostFunction)) or callable(fn)
):
raise RuntimeError(
"op97 non-function at u=%s fn=%r" % (u, fn)
)
raise RuntimeError(f"op97 non-function at u={u} fn={fn!r}")
js_set(C, dest, js_apply(fn, thisv, f))
elif op == 98:
a = o[u + 1]
@@ -1647,10 +1644,10 @@ class VM:
u += 1
js_set(C, a, None)
else:
raise RuntimeError("unknown opcode %s at %s" % (op, u))
raise RuntimeError(f"unknown opcode {op} at {u}")
except _VMThrow as e:
if not d:
raise RuntimeError("VM uncaught throw: %s" % (e.value,))
raise RuntimeError(f"VM uncaught throw: {e.value}")
l = e.value
u = d.pop()
continue
@@ -1658,9 +1655,8 @@ class VM:
if not d:
raise
if not isinstance(d, list):
raise RuntimeError(
"d corrupted: %r (type %s) at trace %s"
% (d, type(d).__name__, self._trace[-3:])
raise TypeError(
f"d corrupted: {d!r} (type {type(d).__name__}) at trace {self._trace[-3:]}"
)
l = e
u = d.pop()
@@ -1746,14 +1742,14 @@ def decode_d(v):
vs = p[ci + 1 :]
try:
obj.set(key, decode_d(json.loads(vs)))
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
obj.set(key, decode_d(vs))
return obj
if v.lstrip("-").isdigit():
return int(v)
try:
return float(v)
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return v