From fa29e0339f2b1d642a8c300059277dae4c2ca7a1 Mon Sep 17 00:00:00 2001 From: shuiyu67 Date: Fri, 7 Aug 2026 02:44:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20L1+L3=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=97=B6=E8=AF=8A=E6=96=AD=E5=85=A8=E9=83=A8=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=20(extend=20=E4=B8=A4=E6=AC=A1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - analyze() 里 issues.extend(analyzer.issues) 被调用两次 → 每条诊断重复出现 - 综合测试发现 20 个问题实际应为 11 个; 修复为只 extend 一次 - 新增回归测试 test_no_duplicate_diagnostics; 276 passed --- plugins/py_detect.py | 3 +-- tests/test_py_detect.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/py_detect.py b/plugins/py_detect.py index e0ccf6e..7b3c08d 100644 --- a/plugins/py_detect.py +++ b/plugins/py_detect.py @@ -686,9 +686,8 @@ def analyze(source: str, filename: str = "") -> List[Dict]: extra=f"重复定义: {name}", name=name, first_line=nodes[0].lineno) - issues.extend(analyzer.issues) _dataflow_check(tree, analyzer) # L3: 数据流 (部分路径未定义) - issues.extend(analyzer.issues) + issues.extend(analyzer.issues) # L1+L3 只 extend 一次, 避免重复 issues = _jedi_validate(source, filename, issues) # L2: 语义二次确认 (可选) return issues diff --git a/tests/test_py_detect.py b/tests/test_py_detect.py index 1215869..b930d47 100644 --- a/tests/test_py_detect.py +++ b/tests/test_py_detect.py @@ -366,6 +366,18 @@ class TestDataFlow: fix = d.get("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 写文件后自动检测集成 ── class TestAutoDetectIntegration: