Skip to content

Commit 036e46a

Browse files
authored
fix(scanner): clean dead-code warnings (#6)
## Summary - remove genuinely unused pickle static scan symbols reported by Skylos - replace dynamic eval-config AST visitor hooks with explicit ast.walk checks so Skylos no longer flags them as unused - add regression coverage for Python assignment, annotated assignment, and dict-literal eval config scanning ## Verification - python -m pytest -q - python -m ruff check . - python -m compileall -q ceres tests scripts - skylos . --quality --no-upload --file-filter ceres/analyzers/model/pickle_static.py --format concise (no dead-code findings remain for this file; other quality findings still reported) - skylos . --quality --no-upload --file-filter ceres/analyzers/eval/safety_config.py --format concise (no dead-code findings remain for this file; other quality findings still reported)
1 parent 8dbacf8 commit 036e46a

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

ceres/analyzers/eval/safety_config.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,21 @@ def _scan_python_file(path: Path, ctx: AnalyzerContext) -> list[Finding]:
134134
rel = ctx.rel(path)
135135
findings: list[Finding] = []
136136

137-
class Visitor(ast.NodeVisitor):
138-
def visit_Assign(self, node: ast.Assign) -> None:
137+
for node in ast.walk(tree):
138+
if isinstance(node, ast.Assign):
139139
for target in node.targets:
140140
key = _target_name(target)
141141
if key:
142142
_check_key_value(key, _literal(node.value), rel, [key], node.lineno, findings, ctx)
143-
self.generic_visit(node)
144-
145-
def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
143+
elif isinstance(node, ast.AnnAssign):
146144
key = _target_name(node.target)
147145
if key:
148146
_check_key_value(key, _literal(node.value), rel, [key], node.lineno, findings, ctx)
149-
self.generic_visit(node)
150-
151-
def visit_Dict(self, node: ast.Dict) -> None:
147+
elif isinstance(node, ast.Dict):
152148
for key_node, value_node in zip(node.keys, node.values):
153149
key = _literal(key_node)
154150
if isinstance(key, str):
155151
_check_key_value(key, _literal(value_node), rel, [key], getattr(node, "lineno", None), findings, ctx)
156-
self.generic_visit(node)
157-
158-
Visitor().visit(tree)
159152
return findings
160153

161154

ceres/analyzers/model/pickle_static.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3+
import pickle
34
import pickletools
45
import zipfile
5-
import pickle
66
from dataclasses import dataclass
77
from pathlib import Path
88

@@ -62,7 +62,7 @@ def scan_pickle_bytes(data: bytes) -> PickleScanResult:
6262
count = 0
6363
truncated = False
6464
try:
65-
for op, arg, _pos in pickletools.genops(data[:_MAX_BYTES]):
65+
for op, arg, _ in pickletools.genops(data[:_MAX_BYTES]):
6666
count += 1
6767
if count > _MAX_OPS:
6868
truncated = True
@@ -76,17 +76,17 @@ def scan_pickle_bytes(data: bytes) -> PickleScanResult:
7676
continue
7777
ref = arg if isinstance(arg, str) else " ".join(arg) if arg else ""
7878
ref_norm = ref.replace(" ", ".")
79-
if _matches_any(ref_norm, _SUSPICIOUS_GLOBALS):
79+
if _matches_any(ref_norm):
8080
suspicious.append(ref_norm)
8181
if name in {"INST", "OBJ"}:
82-
if isinstance(arg, str) and _matches_any(arg.replace(" ", "."), _SUSPICIOUS_GLOBALS):
82+
if isinstance(arg, str) and _matches_any(arg.replace(" ", ".")):
8383
suspicious.append(arg)
8484
except Exception as e: # noqa: BLE001
8585
return PickleScanResult(suspicious, has_reduce, count, truncated, error=str(e))
8686
return PickleScanResult(suspicious, has_reduce, count, truncated)
8787

8888

89-
def _matches_any(ref: str, fragments: set[str]) -> bool:
89+
def _matches_any(ref: str) -> bool:
9090
if ref in _SUSPICIOUS_EXACT:
9191
return True
9292
return any(ref.startswith(prefix) for prefix in _SUSPICIOUS_PREFIXES)

tests/test_correctness_regressions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,20 @@ def test_root_temperature_without_ai_context_is_not_flagged(tmp_path):
139139
cfg.write_text("temperature: 1.4\n")
140140
findings, _suppressed, _counts, _passed, _inv = run_scan(repo, Policy(), None, None)
141141
assert "ceres.eval.generation_temperature_high" in _rule_ids(findings)
142+
143+
144+
def test_eval_safety_python_assignments_are_scanned(tmp_path):
145+
repo = tmp_path / "repo"
146+
src = repo / "src"
147+
src.mkdir(parents=True)
148+
(src / "eval_config.py").write_text(
149+
"skip_safety_eval = True\n"
150+
"enable_content_filter: bool = False\n"
151+
"generation_config = {'temperature': 1.4}\n"
152+
)
153+
154+
findings, _suppressed, _counts, _passed, _inv = run_scan(repo, Policy(), None, None)
155+
rule_ids = _rule_ids(findings)
156+
assert "ceres.eval.safety_eval_disabled" in rule_ids
157+
assert "ceres.eval.safety_filter_disabled" in rule_ids
158+
assert "ceres.eval.generation_temperature_high" in rule_ids

0 commit comments

Comments
 (0)