python-code-review
Reviews Python code for PEP8 compliance, type hints, modern best practices (Python 3.9+), and code quality. Detects anti-patterns, validates documentation, and provides severity-based recommendations. Integrates with modern tooling (ruff, mypy, uv).
What this skill does
# Python Code Review Skill
A specialized skill for reviewing Python code with focus on PEP8 compliance, type hints, modern best practices, and code quality.
## Overview
This skill enables Claude to autonomously review Python code for compliance with modern Python standards, including PEP8 style guidelines, type hint coverage, proper structure, and common anti-patterns. It promotes clean, maintainable, and type-safe Python code.
## Capabilities
When activated, this skill provides:
1. **PEP8 Compliance Review**
- Check naming conventions (snake_case, PascalCase)
- Verify line length (88 characters)
- Review whitespace and indentation
- Check import ordering and grouping
- Validate docstring presence and format
2. **Type Hints Validation**
- Ensure all functions have type hints
- Check for proper return type annotations
- Validate use of modern type syntax (list[], dict[] over List[], Dict[])
- Verify Optional[] vs None union types
- Check for Any types (discourage overuse)
3. **Code Structure & Organization**
- Review module structure and imports
- Check for proper `__init__.py` usage
- Validate entry points (`__main__.py`)
- Review function/class organization
- Assess module coupling and cohesion
4. **Best Practices Enforcement**
- Check for use of context managers (with statements)
- Validate exception handling
- Review string formatting (f-strings preferred)
- Check for proper constant definitions
- Assess use of comprehensions vs loops
5. **Common Anti-Patterns Detection**
- Mutable default arguments
- Bare except clauses
- Using `global` keyword unnecessarily
- Poor variable naming
- Overly complex functions (high cyclomatic complexity)
6. **Documentation Quality**
- Check for docstrings on public functions/classes
- Validate docstring format (Google/NumPy style)
- Review parameter documentation
- Check for return value documentation
- Assess example usage in docstrings
## Usage
This skill activates automatically when:
- User requests: "Review this Python code"
- User asks: "Check PEP8 compliance"
- User mentions: "Validate type hints"
- User wants: "Improve this Python code"
- Code review is requested for .py files
- User asks: "Is this code following best practices?"
## Review Approach
### 1. Initial Assessment
- Identify Python version being used
- Understand the code's purpose
- Determine if it's application code or library code
- Check project structure context
### 2. PEP8 Compliance Check
**Naming Conventions:**
- ✅ Functions/variables: `snake_case`
- ✅ Classes: `PascalCase`
- ✅ Constants: `UPPER_SNAKE_CASE`
- ✅ Private members: `_leading_underscore`
- ✅ Module names: `lowercase` or `snake_case`
**Code Layout:**
- ✅ Line length: 88 characters (Black standard)
- ✅ Indentation: 4 spaces
- ✅ Blank lines: 2 before top-level definitions, 1 between methods
- ✅ Import order: stdlib → third-party → local
- ✅ One import per line (except from imports)
### 3. Type Hints Review
**Check for:**
```python
# ❌ Missing type hints
def process(data):
return data.upper()
# ✅ Proper type hints
def process(data: str) -> str:
return data.upper()
# ❌ Old-style typing (Python <3.9)
from typing import List, Dict
def get_items() -> List[Dict[str, int]]:
pass
# ✅ Modern type syntax (Python 3.9+)
def get_items() -> list[dict[str, int]]:
pass
# ❌ Overuse of Any
from typing import Any
def process(data: Any) -> Any:
pass
# ✅ Specific types
def process(data: str | int) -> str:
return str(data)
```
### 4. Common Issues Detection
**Mutable Default Arguments:**
```python
# ❌ Dangerous
def append_to(element: str, target: list[str] = []) -> list[str]:
target.append(element)
return target
# ✅ Safe
def append_to(element: str, target: list[str] | None = None) -> list[str]:
if target is None:
target = []
target.append(element)
return target
```
**Exception Handling:**
```python
# ❌ Bare except
try:
risky_operation()
except:
pass
# ✅ Specific exception
try:
risky_operation()
except ValueError as e:
logger.error(f"Invalid value: {e}")
raise
```
**String Formatting:**
```python
# ❌ Old style
name = "World"
print("Hello %s" % name)
print("Hello {}".format(name))
# ✅ Modern f-strings
print(f"Hello {name}")
```
**Context Managers:**
```python
# ❌ Manual resource management
file = open("data.txt")
data = file.read()
file.close()
# ✅ Context manager
with open("data.txt") as file:
data = file.read()
```
### 5. Code Quality Assessment
**Function Complexity:**
- Functions should do one thing well
- Aim for <20 lines per function
- Cyclomatic complexity should be low (<10)
- Deep nesting (>3 levels) indicates need for refactoring
**Example - Complex to Simple:**
```python
# ❌ Too complex
def process_user(user):
if user:
if user.active:
if user.email:
if "@" in user.email:
return user.email.lower()
return None
# ✅ Simplified
def process_user(user: User | None) -> str | None:
if not user or not user.active or not user.email:
return None
if "@" not in user.email:
return None
return user.email.lower()
```
## Output Format
Provide review results in this structured format:
```markdown
## Python Code Review Results
### Summary
[Brief overview of the code quality and main findings]
### PEP8 Compliance: [PASS/FAIL/PARTIAL]
**Issues Found:**
- Line 15: Line too long (102 characters, limit 88)
- Line 23: Missing blank line after function definition
- Line 45: Import should be at top of file
### Type Hints Coverage: [X%]
**Missing Type Hints:**
- Line 10: Function `process_data` missing return type
- Line 18: Parameter `config` missing type annotation
- Line 25: Using deprecated `List` instead of `list`
**Recommendations:**
```python
# Current
def process_data(items, limit=10):
return items[:limit]
# Improved
def process_data(items: list[str], limit: int = 10) -> list[str]:
return items[:limit]
```
### Code Quality Issues
#### Critical 🔴
- **Line 34**: Mutable default argument in `add_item(item, items=[])`
- **Line 56**: Bare except clause catching all exceptions
#### Important 🟡
- **Line 12**: Function complexity too high (15 branches)
- **Line 78**: Using `global` keyword - consider refactoring
- **Line 91**: Variable name `x` is not descriptive
#### Minor 🔵
- **Line 23**: Could use f-string instead of .format()
- **Line 45**: List comprehension would be more Pythonic
### Best Practices Violations
1. **Line 15-18: Manual file handling**
- **Current:**
```python
f = open("data.txt")
data = f.read()
f.close()
```
- **Improved:**
```python
with open("data.txt") as f:
data = f.read()
```
2. **Line 34: Mutable default argument**
- **Impact**: Can cause bugs when function is called multiple times
- **Fix**: Use None as default, create new list inside function
### Positive Aspects ✅
- Consistent naming conventions throughout
- Good use of type hints in 80% of functions
- Proper docstrings on all public methods
- Clean import organization
### Documentation Review
- ✅ All public functions have docstrings
- ✅ Docstrings follow Google style format
- ⚠️ Some docstrings missing return value description
- ⚠️ No examples in docstrings (consider adding for complex functions)
### Modernization Suggestions
- Update to Python 3.10+ syntax (use `|` for unions instead of `Union`)
- Consider using `match/case` statement (Python 3.10+) for complex conditionals
- Replace `Dict`, `List` with `dict`, `list` (Python 3.9+)
### Next Steps
1. Fix critical issues (mutable defaults, bare excepts)
2. Add missing type hints
3. Refactor complex functions (>15 lines)
4. Run automated tools:
```bash
uv run ruff check . # Linting
uv run mypy . # Type checking
uv run ruff format . # Auto-formatting
```
### RecommendeRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.