/forgewright:code-reviewer-pythonfrom forgewright
Reviews Python code for type hints, dataclass/pydantic usage, async patterns, exception boundaries, context-manager resource safety, and pytest suites.
Ships in forgewright. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Identity: The quality guardian for Python projects. You extend the base code-reviewer skill with Python-specific patterns, idioms, and anti-patterns.
Auto-route to this skill if project contains:
*.py files AND (pyproject.toml OR requirements.txt OR Pipfile)# ❌ MISSING TYPE HINTS
def process_user(user_id):
return db.fetch(user_id)
# ✅ COMPLETE TYPE HINTS
def process_user(user_id: str) -> User | None:
return await db.fetch(user_id)
# ❌ INCOMPLETE TYPE HINTS
def process_data(data: list):
return [x * 2 for x in data]
# ✅ COMPLETE TYPE HINTS
def process_data(data: list[int]) -> list[int]:
return [x * 2 for x in data]
Review Checklist:
dict[str, int], not Dict)X | None (Python 3.10+) or Optional[X]# ❌ MUTABLE DEFAULT ARGUMENTS
class User:
def __init__(self, name: str, roles: list[str] = []): # DANGER
self.name = name
self.roles = roles
# ✅ USE DATACLASS
from dataclasses import dataclass, field
@dataclass
class User:
name: str
roles: list[str] = field(default_factory=list)
# ❌ PLATFORM DICTIONARY
class Config:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# ✅ PYDANTIC FOR VALIDATION
from pydantic import BaseModel, EmailStr
class UserCreate(BaseModel):
email: EmailStr
name: str
password: str
# ❌ BLOCKING I/O IN ASYNC
async def fetch_users():
users = [] # blocking!
for id in user_ids:
users.append(blocking_db_fetch(id))
return users
# ✅ ASYNC I/O
async def fetch_users():
results = await asyncio.gather(*[
fetch_user(id) for id in user_ids
])
return list(results)
# ❌ NOT CLOSING RESOURCES
async def read_file(path: str) -> str:
f = open(path) # Never closed
return f.read()
# ✅ CONTEXT MANAGER
async def read_file(path: str) -> str:
async with aiofiles.open(path) as f:
return await f.read()
| Error Pattern | Code Smell | Severity |
|---|---|---|
TypeError: 'NoneType' object is not iterable | Missing null check | CRITICAL |
IndentationError | Tab/space mixing | HIGH |
ImportError: cannot import name 'xxx' | Circular import | HIGH |
AttributeError: 'NoneType' | Missing optional handling | CRITICAL |
| Error Pattern | Code Smell | Severity |
|---|---|---|
IndexError: list index out of range | Missing bounds check | MEDIUM |
KeyError | Missing dict key | MEDIUM |
RecursionError | Infinite recursion | MEDIUM |
PendingDeprecationWarning | Using deprecated API | LOW |
# ❌ MUTABLE CLASS ATTRIBUTE
class Service:
cache = {} # Shared across all instances
def get(self, key):
return self.cache.get(key)
# ✅ IMMUTABLE CLASS ATTRIBUTE
class Service:
def __init__(self):
self._cache = {} # Per-instance
@property
def cache(self):
return self._cache
# ❌ MUTABLE DEFAULT ARGUMENT
def add_item(item, items=[]):
items.append(item)
return items
# ✅ PROPER DEFAULT
def add_item(item, items=None):
if items is None:
items = []
items.append(item)
return items
# ❌ BARE EXCEPT
try:
do_something()
except: # Catches everything including SystemExit
pass
# ✅ SPECIFIC EXCEPTIONS
try:
do_something()
except ValueError as e:
logger.error(f"Invalid value: {e}")
except IOError as e:
logger.error(f"IO error: {e}")
# ❌ RAISING STRINGS
if not valid:
raise "Invalid input"
# ✅ RAISING EXCEPTIONS
if not valid:
raise ValueError("Invalid input")
# ❌ SWALLOWING EXCEPTIONS
try:
process(data)
except Exception:
pass # Silent failure
# ✅ PROPER ERROR HANDLING
try:
process(data)
except Exception as e:
logger.error(f"Processing failed: {e}")
raise ProcessingError("Failed to process data") from e
# ❌ SIDE EFFECTS IN LIST COMPREHENSION
results = [expensive_calc(x) for x in items if expensive_filter(x)]
# ✅ CACHE OR USE GENERATOR
cached_filter = {x for x in items if expensive_filter(x)}
results = [expensive_calc(x) for x in cached_filter]
# ❌ NESTED LIST COMPREHENSION (hard to read)
matrix = [[i*j for j in range(5)] for i in range(5)]
# ✅ EXTRACTED FUNCTION
def create_row(i: int) -> list[int]:
return [i*j for j in range(5)]
matrix = [create_row(i) for i in range(5)]
# ❌ UNPYTHONIC LOOP
for i in range(len(items)):
print(items[i])
# ✅ PYTHONIC
for item in items:
print(item)
# ❌ LIST EXTEND WITHOUT EXTEND
for item in new_items:
items.append(item)
# ✅ EXTEND
items.extend(new_items)
# ❌ BUILDING STRINGS WITH +
result = ""
for item in items:
result += str(item) + ", "
# ✅ JOIN
result = ", ".join(str(item) for item in items)
# ❌ CHECKING BOOLEAN WITH LENGTH
if len(items) > 0:
do_something()
# ✅ DIRECT BOOLEAN CHECK
if items:
do_something()
# ❌ BLOCKING DATABASE CALL
@router.post("/users")
async def create_user(user_data: UserCreate):
user = blocking_db_insert(user_data) # Blocks event loop
return user
# ✅ ASYNC DATABASE CALL
@router.post("/users")
async def create_user(
user_data: UserCreate,
service: UserService = Depends(get_user_service)
):
user = await service.create(user_data)
return user
# ❌ NO VALIDATION
@router.post("/items")
async def create_item(data: dict):
return db.insert(data)
# ✅ PYDANTIC VALIDATION
from pydantic import BaseModel
class ItemCreate(BaseModel):
name: str
price: float
quantity: int = 0
@router.post("/items")
async def create_item(data: ItemCreate):
return db.insert(data.model_dump())
# ❌ NO ERROR HANDLING
@router.get("/users/{user_id}")
async def get_user(user_id: str):
return await db.get(user_id)
# ✅ PROPER ERROR HANDLING
from fastapi import HTTPException
@router.get("/users/{user_id}")
async def get_user(user_id: str):
user = await db.get(user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
# ❌ NO REAL ASSERTIONS
def test_user():
user = create_user("[email protected]")
get_user(user.id)
# No assertion!
# ✅ MEANINGFUL ASSERTIONS
def test_user():
user = create_user("[email protected]")
fetched = get_user(user.id)
assert fetched.email == "[email protected]"
assert fetched.name == "Test User"
# ❌ TESTING IMPLEMENTATION
def test_user():
assert len(user._cache) == 1 # Testing internals
# ✅ TESTING BEHAVIOR
def test_user_retrieved():
user = create_user("[email protected]")
fetched = get_user(user.id)
assert fetched is not None
# ❌ SHARED MUTABLE STATE
class TestUser:
user = create_user() # Shared across tests
# ✅ CLEAN FIXTURES
@pytest.fixture
def test_user():
return create_user("[email protected]")
def test_user_email(test_user):
assert test_user.email == "[email protected]"
✓ FOUND - Good Python Project Indicators:
├── pyproject.toml # Modern Python package
├── src/ # Src layout (recommended)
│ └── your_package/
├── tests/ or test/ # Test directory
├── conftest.py # pytest fixtures
├── .python-version # pyenv version
└── requirements*.txt # Dependencies
✗ FOUND - Warning Signs:
├── __init__.py # Empty init files
├── setup.py only # No pyproject.toml
├── *.py files in root # No src layout
├── test_*pyc* # Test files in wrong place
└── venv/ or .venv/ in git # Virtual env committed
| Lint Rule | What It Catches | Severity |
|---|---|---|
E501 | Line too long (> 79/100) | MEDIUM |
F401 | Unused import | MEDIUM |
F841 | Unused variable | LOW |
W0611 | Unused import | LOW |
C0111 | Missing docstring | LOW |
R0913 | Too many arguments | MEDIUM |
R0914 | Too many local variables | MEDIUM |
R0915 | Too many statements | MEDIUM |
C0411 | Wrong import order | LOW |
| Smell | Example | Fix |
|---|---|---|
| God function | > 50 lines, many responsibilities | Split into smaller functions |
| Feature envy | Class accessing another class's data often | Move method to that class |
| Inappropriate intimacy | Two classes deeply coupled | Use interfaces, dependency injection |
| Refused bequest | Inheriting but overriding everything | Use composition instead |
| Data class abuse | Using dataclass for everything | Use regular class for logic |
pyproject.toml, .python-version)src/ layout vs flat structureexcept)print() statements in production codetime.sleep() in testseval() or exec() with user inputsoftware-engineer-python), ML modeling (data-scientist), or formal security pentesting (security-engineer).ruff check, formatter checks, mypy/pyright, and pytest, recording exact file:line findings and Schema v2 tree_sha (VERIFY.md).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
python-review, type-hints, async-patterns, pydantic, dataclass
npx claudepluginhub buiphucminhtam/forgewright --plugin forgewright93 skills in this plugin
/3d-spatial-engineerUse for 3D spatial layouts, scene-graph coordinate transforms, greybox blockouts, culling volumes, static batching, and LOD optimization across 3D game engines./accessibility-engineerUse for web WCAG 2.1/2.2 AA accessibility audits, ARIA semantics, keyboard navigation, focus management, contrast verification, and automated axe-core remediation./ai-behavior-engineerUse for game AI and NPC decision systems: finite state machines, behavior trees, utility AI, GOAP, perception, navigation, tactical steering, and encounter tuning.Other plugins' skills for the same job