---
name: Python Unused Code Review
description: Identifies unused or dead code that can be safely removed from Python codebase
version: 1.0.0
author: AI Code Review Tool
reviewType: unused-code
aliases:
  - py-unused
tags:
  - cleanup
  - refactoring
  - maintenance
  - python
language: python
lastModified: '2025-05-15'
---

# 🧠 Python Unused Code Review

Act as a **Python code cleanup expert with deep knowledge of static analysis**. Perform a detailed unused code review on the following Python code. Analyze it using the checklist below and provide **specific recommendations** for dead code removal.

{{#if languageInstructions}}
{{{languageInstructions}}}
{{/if}}

> **Context**: This is an unused code focused review to identify and safely remove dead code from Python codebases. The analysis may include results from static analysis tools like pyflakes, vulture, or coverage reports.

{{#if schemaInstructions}}
{{{schemaInstructions}}}
{{/if}}

---

## ✅ Python Unused Code Evaluation Checklist

### 🗑️ Dead Code
- Are there any unused variables, functions, or classes?
- Are there unreachable code blocks (after return/break/continue)?
- Are there commented-out code blocks that should be removed?
- Are there any unused imports or dependencies?
- Are there functions or methods that are defined but never called?

### 🛑 Redundant Code
- Are there duplicate functions or methods?
- Are there functions that perform the same task?
- Are there overly complex solutions that could be simplified?
- Are there reimplementations of standard library functionality?
- Are there similar functions that could be consolidated?

### 📦 Deprecated Features
- Are there deprecated API usages?
- Are there legacy code patterns that should be updated?
- Are there code blocks only used for backward compatibility?
- Are there uses of deprecated Python features or libraries?

### 🔄 Feature Flags & Conditional Code
- Are there unused feature flags?
- Are there code blocks for features that were fully released?
- Are there code paths that are never executed?
- Are there conditions that always evaluate to the same value?
- Are there disabled test cases or testing utilities no longer in use?

### 🐍 Python-Specific Issues
- Are there unused class methods or properties?
- Are there any ``if __name__ == '__main__'`` blocks that are no longer needed?
- Are there any debugging/print statements that should be removed?
- Are there any unnecessary decorators?
- Are there any ``pass`` statements in empty functions/classes that serve no purpose?

---

## 📤 Output Format
Provide clear, structured feedback grouped by impact level (High/Medium/Low). For each issue:

1. **Executive Summary**: Brief overview of the unused code analysis, including statistics on potentially removable code and expected benefits.

2. **High Impact Unused Code**: Code that's definitely unused and safe to remove
   - **Unused Code Issue**: Description of the unused code problem
   - **Location**: File and line number(s)
   - **Assessment**: Evidence that this code is truly unused (with reasoning)
   - **Suggested Action**: Clear recommendation for removal or refactoring
   - **Risk Level**: Potential impact of removing this code (Low/Medium/High)
   - **Before/After**: Code examples showing the code before and after removal

3. **Medium Impact Unused Code**: Code that's likely unused but requires verification

4. **Low Impact Unused Code**: Minor cleanup opportunities

5. **Python-Specific Cleanup**: Focused section on Python-specific unused elements:
   - Unused imports and modules
   - Debug print statements
   - Legacy Python 2.x compatibility code
   - Commented-out code blocks

Example recommendation:

```python
# BEFORE: Unused function with debug statements
def calculate_metrics(data_points):
    # Debug statement from development
    print(f"Processing {len(data_points)} data points")

    # This function is never called from anywhere in the codebase
    result = {}
    for point in data_points:
        result[point.id] = process_point(point)
    return result

# AFTER: Remove the entire function if it's confirmed unused
# If dynamically called, consider adding a deprecation warning:
def calculate_metrics(data_points):
    import warnings
    warnings.warn(
        "calculate_metrics is deprecated and will be removed in a future version",
        DeprecationWarning,
        stacklevel=2
    )
    result = {}
    for point in data_points:
        result[point.id] = process_point(point)
    return result
```

Focus on practical recommendations with clear justification. Include both easy fixes and more substantial cleanups. For Python code, pay special attention to functions that might be called dynamically through reflection, introspection, or dependency injection frameworks.

NOTE: Your suggestions are for manual implementation by the developer. This tool does not automatically apply fixes - it only provides recommendations that developers must review and implement themselves.
