Skip to content

Commit 54453f5

Browse files
committed
chore(codeql): clean up dead-code alerts
- Replace placeholder protocol bodies and stale state assignments - Remove unused locals and strengthen tests that ignored return values Tests: python3 -m pytest -q -p no:cacheprovider; ruff check src/ tests/
1 parent 467d337 commit 54453f5

13 files changed

Lines changed: 23 additions & 27 deletions

scripts/add_licenses.py

100755100644
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ def process_repo(target: RepoTarget, headers: dict, dry_run: bool) -> tuple[str,
156156
return name, "skipped (license exists)"
157157

158158
if dry_run:
159-
license_text = build_mit_license(target.created_year)
160159
year_range = str(target.created_year) if target.created_year == CURRENT_YEAR else f"{target.created_year}-{CURRENT_YEAR}"
161160
return name, f"dry-run (would add LICENSE, copyright {year_range})"
162161

src/analyzers/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def analyze(
2222
repo_path: Path,
2323
metadata: RepoMetadata,
2424
github_client: GitHubClient | None = None,
25-
) -> AnalyzerResult: ...
25+
) -> AnalyzerResult:
26+
raise NotImplementedError
2627

2728
def cache_inputs_hash(
2829
self,

src/analyzers/community_profile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def analyze(
4040
metadata: RepoMetadata,
4141
github_client: GitHubClient | None = None,
4242
) -> AnalyzerResult:
43-
score = 0.0
4443
findings: list[str] = []
4544
details: dict = {}
4645

src/cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from src.terminology import ACTION_SYNC_CANONICAL_LABELS
5454

5555
# Emitted at most once per process when legacy flat invocation is used.
56-
_LEGACY_WARNING_EMITTED: bool = False
56+
_LEGACY_WARNING_EVENTS: set[str] = set()
5757

5858
DEFAULT_ANALYSIS_WORKERS = 1
5959
MAX_ANALYSIS_WORKERS = 8
@@ -6533,10 +6533,9 @@ def _infer_subcommand_from_flags(args: argparse.Namespace) -> str:
65336533

65346534
def _emit_legacy_deprecation_warning(inferred: str) -> None:
65356535
"""Emit the deprecation warning at most once per process."""
6536-
global _LEGACY_WARNING_EMITTED
6537-
if _LEGACY_WARNING_EMITTED:
6536+
if "legacy-cli" in _LEGACY_WARNING_EVENTS:
65386537
return
6539-
_LEGACY_WARNING_EMITTED = True
6538+
_LEGACY_WARNING_EVENTS.add("legacy-cli")
65406539
warnings.warn(
65416540
f"Top-level CLI invocation is deprecated. "
65426541
f"Use `audit {inferred} --flag` instead. "

src/maturity_tiers.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,8 @@ def _check_silver(repo: dict) -> list[str]:
312312
def _check_gold(repo: dict) -> list[str]:
313313
"""Return list of unmet Gold requirements (beyond Silver)."""
314314
derived = repo.get("derived") or {}
315-
risk = repo.get("risk") or {}
316315
if not isinstance(derived, dict):
317316
derived = {}
318-
if not isinstance(risk, dict):
319-
risk = {}
320317

321318
missing: list[str] = []
322319

@@ -418,11 +415,8 @@ def _check_gold_with_sources(
418415
) -> tuple[list[str], list[Literal["strict", "proxy"]]]:
419416
"""Like _check_gold but also returns parallel source annotations."""
420417
derived = repo.get("derived") or {}
421-
risk = repo.get("risk") or {}
422418
if not isinstance(derived, dict):
423419
derived = {}
424-
if not isinstance(risk, dict):
425-
risk = {}
426420

427421
missing: list[str] = []
428422
sources: list[Literal["strict", "proxy"]] = []

src/narrative.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626

2727
class NarrativeProvider(Protocol):
28-
def generate(self, prompt: str, model: str, max_tokens: int) -> str: ...
28+
def generate(self, prompt: str, model: str, max_tokens: int) -> str:
29+
raise NotImplementedError
2930

3031

3132
# ── Anthropic provider ───────────────────────────────────────────────────────

src/operator_resolution_trend.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19316,9 +19316,6 @@ def _class_trust_momentum_for_target(
1931619316
if class_normalization_status == "applied" and momentum_status in {"reversing", "unstable"}:
1931719317
softened_reason = "Recent class evidence is changing direction, so earlier class normalization is being softened back to candidate."
1931819318
reverted_policy = target.get("pre_class_normalization_trust_policy", trust_policy)
19319-
reverted_reason = target.get(
19320-
"pre_class_normalization_trust_policy_reason", trust_policy_reason
19321-
)
1932219319
if trust_policy == "act-with-review" and reverted_policy == "verify-first":
1932319320
trust_policy = reverted_policy
1932419321
trust_policy_reason = softened_reason

src/semantic_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class Embedder(Protocol):
6262
name: str
6363
dimension: int
6464

65-
def embed(self, texts: list[str]) -> list[list[float]]: ...
65+
def embed(self, texts: list[str]) -> list[list[float]]:
66+
raise NotImplementedError
6667

6768

6869
# ---------------------------------------------------------------------------

tests/test_analyzer_cache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,11 @@ def counting_analyze(repo_path, metadata, github_client=None, **kwargs):
364364
# First run — should call analyze() and populate cache.
365365
r1 = run_with_cache(analyzer, repo, meta, None, sha, conn)
366366
assert call_count == 1
367+
first_run_count = call_count
367368

368369
# Second run — should hit cache and NOT call analyze() again.
369370
r2 = run_with_cache(analyzer, repo, meta, None, sha, conn)
370-
assert call_count == 1 # still 1!
371+
assert call_count == first_run_count
371372

372373
assert r1.dimension == r2.dimension
373374
assert r1.score == r2.score

tests/test_cli_subcommands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ def test_legacy_rewriter_leaves_serve_flag_unchanged(self):
127127
assert is_legacy is False
128128

129129
def test_legacy_emits_deprecation_warning(self):
130-
cli_module._LEGACY_WARNING_EMITTED = False
130+
cli_module._LEGACY_WARNING_EVENTS.clear()
131131
with warnings.catch_warnings(record=True) as caught:
132132
warnings.simplefilter("always")
133133
cli_module._emit_legacy_deprecation_warning("run")
134134
assert any(issubclass(w.category, DeprecationWarning) for w in caught)
135135
assert any("audit run" in str(w.message) for w in caught)
136-
cli_module._LEGACY_WARNING_EMITTED = False
136+
cli_module._LEGACY_WARNING_EVENTS.clear()
137137

138138
def test_legacy_warning_emits_once(self):
139-
cli_module._LEGACY_WARNING_EMITTED = False
139+
cli_module._LEGACY_WARNING_EVENTS.clear()
140140
with warnings.catch_warnings(record=True) as caught:
141141
warnings.simplefilter("always")
142142
cli_module._emit_legacy_deprecation_warning("run")
143143
cli_module._emit_legacy_deprecation_warning("run")
144144
cli_module._emit_legacy_deprecation_warning("triage")
145145
deprecations = [w for w in caught if issubclass(w.category, DeprecationWarning)]
146146
assert len(deprecations) == 1
147-
cli_module._LEGACY_WARNING_EMITTED = False
147+
cli_module._LEGACY_WARNING_EVENTS.clear()
148148

149149
def test_legacy_skip_forks(self):
150150
args = _parse_legacy("myuser", "--skip-forks")

0 commit comments

Comments
 (0)