Expand description
Cohesion command - LCOM4 (Lack of Cohesion of Methods) analysis for Python classes.
LCOM4 measures class cohesion by counting connected components in the method-field graph:
- LCOM4 = 1: All methods are connected (cohesive class)
- LCOM4 > 1: Methods form disconnected groups (split candidate)
§Algorithm
- Parse class, extract methods and field accesses (
self.x) - Build bipartite graph: methods <-> fields they access
- Add edges for intra-class method calls (
self.method()) - Count connected components via union-find with path compression
§TIGER Mitigations
- T06: Union-find with path compression AND union by rank
- E01:
--timeoutflag (default 30s) - E04:
MAX_METHODS_PER_CLASSandMAX_FIELDS_PER_CLASSlimits - E05:
MAX_ITERATIONSfor union-find operations
§Example
tldr cohesion src/models.py
tldr cohesion src/models.py --min-methods 3 --include-dunder
tldr cohesion src/ --format textStructs§
- Cohesion
Args - Compute LCOM4 (Lack of Cohesion of Methods) metric for Python classes.
- Union
Find - Union-Find (Disjoint Set Union) data structure with path compression and union by rank.
Enums§
- Output
Format - Output format for cohesion command
Functions§
- format_
cohesion_ text - Format a cohesion report as human-readable text.
- run
- Run cohesion analysis (for programmatic use).