fix: 标准库压测修复 (walrus 登记 + match/case 绑定 + import* 提示)
- _flow_check_loads: NamedExpr(walrus) 先登记 target → ast.py end_lineno / doctest.py loader 误报消除 - _match_bound_names: match/case 模式绑定变量收集 (MatchAs/MatchStar/MatchMapping/MatchSequence/MatchClass), L1+L3 双收集 → dataclasses iterable 误报消除 - import * 文件: E002 补提示「可能来自星号导入」 (ast.py Expression 等) - 剩余 E004 为固有盲区: 数值条件关联(difflib best_ratio<cutoff 恒真) / 闭包 / locals() 防御, 需符号执行级别, 接受 - 新增 3 项回归测试; 291 passed
This commit is contained in:
1 parent
9badbf30b7
commit
7494d57aec
2 files changed
+88
No files matched your search
@@ -472,6 +472,34 @@ class TestDataFlow:
|
||||
" return exc[:2] + (tb,)\n")
|
||||
assert "E004" in {d["code"] for d in pd.analyze(src, "t.py")}
|
||||
|
||||
# ── 标准库压测发现的回归 (walrus / match-case) ──
|
||||
def test_walrus_in_condition_ok(self, pd):
|
||||
"""(x := ...) 在 if 条件里 → x 在 if 体内确定 (ast.py end_lineno 场景)"""
|
||||
src = ("def f(node):\n"
|
||||
" if 'end' in node._attributes and (end := getattr(node, 'end', 0)) is not None:\n"
|
||||
" node.end = end + 1\n"
|
||||
" return node\n")
|
||||
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
|
||||
|
||||
def test_match_case_bind_ok(self, pd):
|
||||
"""match/case 模式绑定变量在其 body 内确定 (dataclasses iterable 场景)"""
|
||||
src = ("def f(v):\n"
|
||||
" match v:\n"
|
||||
" case iterable if not hasattr(iterable, '__next__'):\n"
|
||||
" return iterable\n"
|
||||
" case _:\n"
|
||||
" return None\n")
|
||||
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
|
||||
|
||||
def test_match_after_use_ok(self, pd):
|
||||
src = ("def h(v):\n"
|
||||
" match v:\n"
|
||||
" case [a, b]:\n"
|
||||
" return a + b\n"
|
||||
" case _:\n"
|
||||
" return 0\n")
|
||||
assert "E004" not in {d["code"] for d in pd.analyze(src, "t.py")}
|
||||
|
||||
|
||||
# ── code_editor 写文件后自动检测集成 ──
|
||||
class TestAutoDetectIntegration:
|
||||
|
||||
Reference in new issue
Block a user