fix: 修复 L1+L3 合并时诊断全部重复 (extend 两次)
- analyze() 里 issues.extend(analyzer.issues) 被调用两次 → 每条诊断重复出现 - 综合测试发现 20 个问题实际应为 11 个; 修复为只 extend 一次 - 新增回归测试 test_no_duplicate_diagnostics; 276 passed
This commit is contained in:
1 parent
413f66deb8
commit
fa29e0339f
2 files changed
+13
-2
No files matched your search
@@ -686,9 +686,8 @@ def analyze(source: str, filename: str = "<string>") -> List[Dict]:
|
|||||||
extra=f"重复定义: {name}",
|
extra=f"重复定义: {name}",
|
||||||
name=name, first_line=nodes[0].lineno)
|
name=name, first_line=nodes[0].lineno)
|
||||||
|
|
||||||
issues.extend(analyzer.issues)
|
|
||||||
_dataflow_check(tree, analyzer) # L3: 数据流 (部分路径未定义)
|
_dataflow_check(tree, analyzer) # L3: 数据流 (部分路径未定义)
|
||||||
issues.extend(analyzer.issues)
|
issues.extend(analyzer.issues) # L1+L3 只 extend 一次, 避免重复
|
||||||
issues = _jedi_validate(source, filename, issues) # L2: 语义二次确认 (可选)
|
issues = _jedi_validate(source, filename, issues) # L2: 语义二次确认 (可选)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|||||||
@@ -366,6 +366,18 @@ class TestDataFlow:
|
|||||||
fix = d.get("fix", "")
|
fix = d.get("fix", "")
|
||||||
assert "result = None" in fix, fix
|
assert "result = None" in fix, fix
|
||||||
|
|
||||||
|
def test_no_duplicate_diagnostics(self, pd):
|
||||||
|
"""L1+L3 合并不得产生重复诊断 (回归: 曾因 extend 两次全部重复)"""
|
||||||
|
src = ("import os\n"
|
||||||
|
"from math import *\n"
|
||||||
|
"def f(flag):\n"
|
||||||
|
" if flag:\n"
|
||||||
|
" r = build()\n"
|
||||||
|
" return r\n")
|
||||||
|
issues = pd.analyze(src, "t.py")
|
||||||
|
keys = [(d["code"], d["line"], d["col"]) for d in issues]
|
||||||
|
assert len(keys) == len(set(keys)), f"存在重复诊断: {keys}"
|
||||||
|
|
||||||
|
|
||||||
# ── code_editor 写文件后自动检测集成 ──
|
# ── code_editor 写文件后自动检测集成 ──
|
||||||
class TestAutoDetectIntegration:
|
class TestAutoDetectIntegration:
|
||||||
|
|||||||
Reference in new issue
Block a user