fix: 顶级库压测 (pydantic/fastapi/click) 修复 posonlyargs/常量迭代源/for-else 终止

- posonlyargs (/ 位置专用参数) 漏收集 → pydantic 45 个 E002 归零 (config.py class_、networks.py input_value)
- 常量非空迭代源 for x in ('a','b','c')/range(n>0): 循环体必执行 → 变量确定 (pydantic v1 host)
- for-else else 终止 → 仅 break 路径流出 → 循环变量确定 (click/utils.py i)
- 效果: pydantic E002 45→0 E004 18→7 (剩闭包盲区); Web 栈 E004 27→22; 新增 3 回归测试; 302 passed
This commit is contained in:
shuiyu67 committed 2026-08-07 08:50:31 +08:00
1 parent 082efd62cc
commit e16234aba9
2 files changed
+70 -6

No files matched your search

+22
View File
@@ -572,6 +572,28 @@ class TestDataFlow:
assert "E002" not in {d["code"] for d in pd.analyze(src, "t.py")}
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
# ── 顶级库压测回归 (posonlyargs / 常量迭代源) ──
def test_posonly_args_collected(self, pd):
"""def f(a, /, b): a 是位置专用参数, 不得误报 (pydantic Self | str 场景)"""
src = ("def inner(class_, /):\n"
" return class_.__name__\n")
assert "E002" not in {d["code"] for d in pd.analyze(src, "t.py")}
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
def test_const_iter_always_runs(self, pd):
"""for f in ('a','b','c'): 常量非空 → 循环变量确定 (pydantic v1 host 场景)"""
src = ("def f(parts):\n"
" for k in ('a', 'b', 'c'):\n"
" host = parts[k]\n"
" if host:\n"
" break\n"
" return host\n")
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
def test_range_const_iter(self, pd):
src = "def f():\n for i in range(3):\n x = i\n return x\n"
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
# ── code_editor 写文件后自动检测集成 ──
class TestAutoDetectIntegration: