feat(dead-code): report unreachable classes via INSTANTIATES and INHERITS reachability#544
Conversation
…RITS reachability
There was a problem hiding this comment.
Code Review
This pull request introduces support for identifying unreachable classes in the dead-code analysis tool. It adds a new --classes CLI option, introduces an INSTANTIATES relationship type to track class construction (especially for classes without an explicit __init__ method), and updates the Cypher query generation to traverse INSTANTIATES and INHERITS relationships when the classes flag is enabled. Comprehensive unit and integration tests have been added to verify these changes. I have no further feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Greptile SummaryThis PR adds class-aware dead-code reporting. The main changes are:
Confidence Score: 5/5The changes appear merge-safe with no code issues identified. The implementation is well-scoped, covered by targeted tests, and no blocking correctness concerns were found in the changed code.
What T-Rex did
Reviews (2): Last reviewed commit: "docs(dead-code): clarify base classes ar..." | Re-trigger Greptile |
|
@greptile review |
Summary
Adds class-level dead-code detection to
cgr dead-codevia a new--classesflag, backed by a newINSTANTIATESrelationship. This preserves the existing invariant thatCALLSonly ever targets functions and methods (never a class node).What changed
INSTANTIATESrelationship ((Module|Function|Method) -[INSTANTIATES]-> (Class)): class construction now emitsINSTANTIATES -> classfor every construction, plusCALLS -> __init__only when the class defines one. Classless constructions (dataclass / NamedTuple / pydantic) are represented byINSTANTIATESalone, soCALLSstays function/method-only.--classes/--no-classesflag (off by default). When on, reachability walks[:CALLS|INSTANTIATES|INHERITS*0..]and module-load roots are reached via[:CALLS|INSTANTIATES], so a class is reported only when nothing instantiates or subclasses it.INSTANTIATESedges so classless construction keeps recall at 1.0.Caveats (documented in
--classeshelp)Classes referenced only via type annotations,
isinstance, or dynamic lookups are not modelled as edges, so class candidates are review hints, not a guaranteed delete list.Verification
ruff,ty(no new diagnostics vs main), andcheck_no_docs.pyall clean locally.__init__, an inheritance pair, and an orphan class reports only the orphan under--classes; all instantiated/subclassed classes are correctly live.