2.9 KiB
2.9 KiB
Review Checklist
Full criteria for categorizing findings in the Python review skill.
🔴 Must Fix — Correctness & Type Safety
These block merge. Apply by default.
mypy strict violations
error:any mypy error (all are must-fix under strict mode)- Implicit
Any— untyped function parameters or return values type: ignorewithout a specific error code (e.g. bare# type: ignore)- Incompatible types in assignment or return
- Missing
--strictcompatibility: missingpy.typed, missing stubs
Logic & Security (manual review)
- Mutable default arguments:
def f(x: list = [])→ useNone+ guard - Shadowing built-ins:
list,dict,id,type,input, etc. - Uncaught exceptions from external I/O without explicit handling
- SQL/shell injection risks (string formatting into queries/commands)
- Hardcoded secrets or credentials
assertused for runtime validation (stripped with-O)
🟡 Should Fix — Code Quality
These hurt maintainability. Fix unless explicitly skipped.
ruff violations (common)
E501— line too long (respectline-lengthfrom pyproject.toml)F401— unused importF841— local variable assigned but never usedB006— mutable argument defaultB007— loop variable unusedUPprefix — pyupgrade rules (use modern Python syntax)SIMprefix — simplifiable conditionsRUFprefix — Ruff-specific best practices
Manual quality
- Missing return type annotation on public functions/methods
- Missing docstring on public API (classes, public methods, module)
passinexceptblock without a comment explaining whyprint()left in production code (uselogging)- Overly broad
except Exceptionwithout re-raise or specific handling - Dead code: unreachable branches, commented-out code blocks
🟢 Consider — Optimization & Modern Python 3.13+
Suggestions only. Offer but don't apply without confirmation.
Python 3.13+ idioms
- Use
type X = ...(PEP 695) instead ofTypeAlias - Use
X | Yunion syntax instead ofUnion[X, Y]orOptional[X] - Use
TypeVarwithtypestatement (PEP 695) instead of oldTypeVar() @overridedecorator (PEP 698) for overriding methodstomllib(stdlib) instead of third-party TOML parserspathlib.Pathinstead ofos.pathstring operations
Performance
- Generator expressions instead of list comprehensions when result is iterated once
__slots__on data-heavy classes to reduce memoryfunctools.cache/functools.lru_cachefor pure deterministic functions- Avoid repeated attribute lookup in tight loops (
local = self.attr) - Prefer
collections.dequeoverlistfor O(1) pop from front
Readability
- Replace long
if/elifchains withmatch/case(structural pattern matching) - Extract deeply nested logic into named helper functions
- Use
dataclasses.dataclassorpydantic.BaseModelfor plain data containers - Named tuples or
TypedDictinstead of untypeddictreturns