Python review checklist
Use this when writing or reviewing Python code. The severities say how serious a problem is; they are guidance for a finding's severity, not a verdict.
Review Priorities
CRITICAL — Security
- SQL Injection: f-strings in queries — use parameterized queries
- Command Injection: unvalidated input in shell commands — use subprocess with list args
- Path Traversal: user-controlled paths — validate with normpath, reject
..
- Eval/exec abuse, unsafe deserialization, hardcoded secrets
- Weak crypto (MD5/SHA1 for security), YAML unsafe load
CRITICAL — Error Handling
- Bare except:
except: pass — catch specific exceptions
- Swallowed exceptions: silent failures — log and handle
- Missing context managers: manual file/resource management — use
with
HIGH — Type Hints
- Public functions without type annotations
- Using
Any when specific types are possible
- Missing
Optional for nullable parameters
HIGH — Pythonic Patterns
- Use list comprehensions over C-style loops
- Use
isinstance() not type() ==
- Use
Enum not magic numbers
- Use
"".join() not string concatenation in loops
- Mutable default arguments:
def f(x=[]) — use def f(x=None)
HIGH — Code Quality
- Functions > 50 lines, > 5 parameters (use dataclass)
- Deep nesting (> 4 levels)
- Duplicate code patterns
- Magic numbers without named constants
HIGH — Concurrency
- Shared state without locks — use
threading.Lock
- Mixing sync/async incorrectly
- N+1 queries in loops — batch query
MEDIUM — Best Practices
- PEP 8: import order, naming, spacing
- Missing docstrings on public functions
print() instead of logging
from module import * — namespace pollution
value == None — use value is None
- Shadowing builtins (
list, dict, str)
Diagnostic Commands
mypy . # Type checking
ruff check . # Fast linting
black --check . # Format check
bandit -r . # Security scan
pytest --cov=app --cov-report=term-missing # Test coverage
Framework Checks
- Django:
select_related/prefetch_related for N+1, atomic() for multi-step, migrations
- FastAPI: CORS config, Pydantic validation, response models, no blocking in async
- Flask: Proper error handlers, CSRF protection
Reference
For detailed Python patterns, security examples, and code samples, see skill: python-patterns.
Review with the mindset: "Would this code pass review at a top Python shop or open-source project?"
1---2name: python-review3description: Python review checklist — what to check in Python code, by severity. A reference for writing and reviewing it; in a workflow run the review step records each problem as a finding and the engine decides what blocks.4allowed-tools: Read, Grep, Glob, Bash5tags: [stack:python, review]6metadata:7 source: https://skillmd.com/skills/keyvaluesoftwaresystems/python-review8---910# Python review checklist1112Use this when writing or reviewing Python code. The severities say how serious a problem is; they are guidance for a finding's severity, not a verdict.1314## Review Priorities1516### CRITICAL — Security17- **SQL Injection**: f-strings in queries — use parameterized queries18- **Command Injection**: unvalidated input in shell commands — use subprocess with list args19- **Path Traversal**: user-controlled paths — validate with normpath, reject `..`20- **Eval/exec abuse**, **unsafe deserialization**, **hardcoded secrets**21- **Weak crypto** (MD5/SHA1 for security), **YAML unsafe load**2223### CRITICAL — Error Handling24- **Bare except**: `except: pass` — catch specific exceptions25- **Swallowed exceptions**: silent failures — log and handle26- **Missing context managers**: manual file/resource management — use `with`2728### HIGH — Type Hints29- Public functions without type annotations30- Using `Any` when specific types are possible31- Missing `Optional` for nullable parameters3233### HIGH — Pythonic Patterns34- Use list comprehensions over C-style loops35- Use `isinstance()` not `type() ==`36- Use `Enum` not magic numbers37- Use `"".join()` not string concatenation in loops38- **Mutable default arguments**: `def f(x=[])` — use `def f(x=None)`3940### HIGH — Code Quality41- Functions > 50 lines, > 5 parameters (use dataclass)42- Deep nesting (> 4 levels)43- Duplicate code patterns44- Magic numbers without named constants4546### HIGH — Concurrency47- Shared state without locks — use `threading.Lock`48- Mixing sync/async incorrectly49- N+1 queries in loops — batch query5051### MEDIUM — Best Practices52- PEP 8: import order, naming, spacing53- Missing docstrings on public functions54- `print()` instead of `logging`55- `from module import *` — namespace pollution56- `value == None` — use `value is None`57- Shadowing builtins (`list`, `dict`, `str`)5859## Diagnostic Commands6061```bash62mypy . # Type checking63ruff check . # Fast linting64black --check . # Format check65bandit -r . # Security scan66pytest --cov=app --cov-report=term-missing # Test coverage67```6869## Framework Checks7071- **Django**: `select_related`/`prefetch_related` for N+1, `atomic()` for multi-step, migrations72- **FastAPI**: CORS config, Pydantic validation, response models, no blocking in async73- **Flask**: Proper error handlers, CSRF protection7475## Reference7677For detailed Python patterns, security examples, and code samples, see skill: `python-patterns`.7879---8081Review with the mindset: "Would this code pass review at a top Python shop or open-source project?"