python-impossible-states-mining
Mine Python classes that make illegal states representable
# python-impossible-states-mining
For background on this miner, see this [blog post](https://codemod.com/blog/continuous-code-health-auditing-at-scale).
Read-only miner for Python classes that **make illegal states representable**. If a dataclass has `is_pending`, `is_running`, `is_failed`, and `is_done`, or `is_loading` + `is_error` + `data` on the same object, this is the scan.
It never edits source. Every hit is one `py_impossible_state` metric row. Treat findings as review candidates — an `Enum`, a tagged union, or splitting the payload out may be the right fix. The miner cannot decide that.
## Metric
**Name:** `py_impossible_state`
| Cardinality | Values |
| ------------- | --------------------------------------------------------- |
| `rule_id` | detector id |
| `category` | `state_representation` |
| `confidence` | `high`, `medium`, `low` (match-strength, not probability) |
| `file_path` | target-relative path |
| `line_number` | 1-based |
| `symbol` | class name |
| `details` | optional sorted `key=value` pairs (cap ~80 chars) |
## Catalog
| `rule_id` | Category | Confidence | What it matches |
| ---------------------- | ---------------------- | ---------- | ------------------------------------------------------------------------------------------------------------ |
| `boolean_flag_cluster` | `state_representation` | medium | ≥3 `is_`/`has_`/`can_`/`should_` boolean fields on one class or `@dataclass` |
| `async_status_triple` | `state_representation` | high | ≥2 of `{is_loading,is_error,is_success,is_idle,is_pending,…}` plus `data`/`error`/`result` on the same class |
## What it ignores
- Independent flags (`disabled`, `hidden`, `required`) that do not use the `is_`/`has_`/`can_`/`should_` prefix
- A single `is_loading` next to `data`
- Cross-file duplicated shapes, abort/generation-counter bugs, module-boundary advice