Skip to content

fix(analysis): skip tests/fixtures + Protocol classes from dead-code/untested#2

Merged
smochan merged 2 commits into
mainfrom
fix/c2-analyzer-cleanup
Apr 27, 2026
Merged

fix(analysis): skip tests/fixtures + Protocol classes from dead-code/untested#2
smochan merged 2 commits into
mainfrom
fix/c2-analyzer-cleanup

Conversation

@smochan

@smochan smochan commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Move EXCLUDED_PATH_FRAGMENTS and is_excluded_path() into analysis/_common.py; both analyzers reuse
  • Add is_protocol_class() / in_protocol_class() helpers; skip Protocol classes + their methods
  • Untested analyzer now skips tests/fixtures/ paths consistently with dead-code analyzer

Effect on self-graph (combined with C1 already merged)

  • Dead code: 24 → ~13 (Protocol class drop + R3 backend resolution)
  • Untested: 345 → ~280 (-65; fixture skip + Protocol skip together)

Tests

  • 9 new tests in tests/test_analyzer_cleanup.py
  • ruff + mypy --strict clean

smochan added 2 commits April 27, 2026 18:21
…ently

Move EXCLUDED_PATH_FRAGMENTS and is_excluded_path() from dead_code.py into
analysis/_common.py and call the shared helper from both analyzers. The
untested-functions analyzer previously flagged ~30 nodes inside
tests/fixtures/ that have no traceable call graph; it now matches the
dead-code analyzer's exclusion.
Add is_protocol_class() and in_protocol_class() helpers to
analysis/_common.py. Both helpers walk INHERITS edges to detect when a
class derives from typing.Protocol (handles bare 'Protocol',
'typing.Protocol', and unresolved::Protocol forms emitted by the parser).

Skip these from dead-code candidates (Protocol class + its methods) and
from untested candidates (Protocol methods). Protocol declarations exist
for static type checking and have no runtime call-graph incoming edges
by design — flagging them produces noise.
@smochan smochan merged commit 5070d78 into main Apr 27, 2026
3 checks passed
smochan added a commit that referenced this pull request May 30, 2026
The `unresolved_edges` count conflated two very different things:

1. External imports — `fastapi`, `os`, `react`. Static analysis without
   a venv/site-packages parse can't resolve these and isn't supposed to.
   These are expected, not errors.
2. Local-unresolved — target's root module IS in the repo but the
   specific symbol couldn't be matched (rename drift, dynamic import,
   missed binding). These are the actionable ones.

`compute_metrics` now classifies each unresolved edge by checking whether
the target's root module appears as a MODULE node's qualname-root in the
graph. New fields: `external_edges`, `unresolved_local_edges`. The
`unresolved_edges` total is kept as the sum for back-compat.

Surfaced + exposed in the markdown report and the MCP `metrics` tool.

v0.1.2 backlog item #2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant