Sub topic 14
A reusable review checklist
This chapter assumes you can read a Git diff, write and run unit tests, and have used an AI coding assistant. It turns the earlier review steps into one checklist you can reuse on every change.
Why a checklist
Reviews fail in predictable ways. You skim because the code looks tidy. You check the part you like and skip the part you don't. A checklist fixes the order and the questions, so a review doesn't depend on your mood or on how much time you have.
The checklist has two parts. Part one is quick checks that take a minute. Part two is evidence you collect by running things.
The checklist
Work through the items in order. Stop and revise as soon as one fails, because later checks assume the earlier ones passed.
- Intent. Can you state the requirement in one sentence? Does the change do that and nothing more?
- Scope. Is the diff small enough to read in one sitting? Are there unrelated edits, renamed files, or reformatted code?
- Dependencies and APIs. Does every new import exist, and is it the package you meant? Does every called function exist in the version you use?
- Correctness. What happens with empty, null, very large, or malformed input? Are errors raised or silently swallowed?
- Security. Is any input put into SQL, shell commands, or file paths? Are there hardcoded secrets? Is input validated where it enters?
- Tests. Do tests cover the requirement and the edge cases? Did you watch them fail before the fix and pass after?
- Static analysis. Do the linter and type checker pass without new suppressions?
- Maintainability. Does the code follow your naming, structure, and existing helpers, or does it duplicate them?
- Performance. Is there a query inside a loop, an unbounded list, or a resource that is never closed?
Running the evidence checks
Commands give you facts that the code's appearance can't. Start by seeing what changed, then stage only what you have reviewed.
git diff --stat
git diff
git add -pgit diff --stat shows which files changed and how much. git add -p walks through each hunk, so you accept pieces one at a time instead of taking the whole change.
Then run your tests, linter, and type checker. A typical project might use these:
pytest
ruff check .
mypy .Record the result of each. "Looks fine" is not a result. "pytest: 42 passed, mypy: no errors" is.
Applying it to a small example
An assistant wrote this function for "return the average of a list of scores":
def average(values):
return sum(values) / len(values)Item 4 catches it. An empty list raises ZeroDivisionError, and the requirement never said what should happen. You decide the behavior, then pin it with tests (item 6):
import pytest
def average(values):
if not values:
raise ValueError("values must not be empty")
return sum(values) / len(values)
def test_average_of_numbers():
assert average([2, 4, 6]) == 4
def test_average_of_empty_list_raises():
with pytest.raises(ValueError):
average([])Making the decision
The checklist ends in one of three outcomes:
| Outcome | When it applies | Next step |
|---|---|---|
| Accept | Every item passes and you have recorded evidence | Commit the reviewed hunks |
| Revise | Small, fixable failures, such as a missing edge case | Fix by hand or give the assistant a specific correction, then restart the checklist |
| Reject | The approach is wrong, the scope is too large, or you can't verify it | Discard the change and re-ask with a narrower prompt |
After a revision, rerun the checklist from the top. A fix can break an earlier item.
Exercise
An assistant adds a feature in a 900-line diff that also reformats two unrelated files. The tests pass. Which checklist item fails first, and what do you do?
Show answer
Scope (item 2) fails first, because the diff is too large and includes unrelated edits. Passing tests don't change that. Reject or split the change: ask for the feature alone in a smaller diff, and keep the reformatting in a separate commit, then restart the checklist.
Exercise
You review a function and the linter, type checker, and tests all pass. You then notice it builds a SQL query with an f-string around user input. Do you accept it? Why?
Show answer
No. Security (item 5) fails, and tools passing doesn't override a failed item. String-built SQL allows injection. Revise it to use a parameterized query, for example conn.execute("SELECT id, name FROM users WHERE name = ?", (name,)), add a test with an input like ' OR '1'='1, and rerun the checklist.