Your starting point
A review note that names the failure, shows a reproducible case and explains why the smallest repair works.
Before you begin. Python 3.10 or later, a terminal and an empty practice directory. The exercise uses only the Python standard library and fictional products. It needs no API key, model subscription or downloaded project.
Product details and verification
The repository presents deliberately buggy Python and JavaScript code with a documented exercise-checking workflow. Source ↗
Current’s original Python fixture was executed locally with Python 3.9.6 on October 17: the proposed function failed two of four checks; the repair passed all four. WouldYouMerge repository code and any AI reviewer were not executed.
A short function can return the right answer on its first call and still be unsafe to merge. Code review gets more useful when you can explain the sequence that breaks it. This exercise turns that sequence into a test another person can repeat.
WouldYouMerge is a public collection of intentionally buggy Python and JavaScript review exercises. Its README prompted this original example. The code below was written for Current and is independent of the repository’s implementation. The external project was read but was not executed.
1. Write the behavior before reading the implementation
The fictional shop needs a quote total in cents. A call supplies a product identifier, an integer unit price and a non-negative integer quantity. For this exercise the inputs are already validated; the result must equal unit price multiplied by quantity. Every call uses its own arguments, even when an earlier call used the same product identifier.
That last sentence is the important contract. Prices can change, and a customer can edit the quantity. A result retained from a previous call must never override the current request. Tax, discounts, rounding, currencies and persistence are outside this small function. Keep those boundaries explicit so you can judge the proposed change without redesigning a checkout system.
Create an empty directory named quote-review and open a terminal there. Check python3 --version. If your system only exposes python, use that command consistently after confirming it is Python 3.10 or later. Save the next two code blocks as plain UTF-8 files in this directory. No package installation is required.
2. Inspect the proposal and write down one suspicion
class QuoteBook:
def __init__(self):
self.cache = {}
def total(self, sku, unit_price_cents, quantity):
if sku not in self.cache:
self.cache[sku] = unit_price_cents * quantity
return self.cache[sku]Read the function once without running it. Write a short prediction: which arguments influence the result, and which of them influence the cached value’s identity? A cache stores an earlier result for reuse. Here the dictionary is indexed only by the product identifier. Your job is to decide whether that stored result remains valid after the other inputs change.
If you use an AI assistant for this step, give it the contract and quote.py, then the prompt below. Keep the tests and repair hidden during its first review. Save the original response so you can distinguish a genuine finding from an explanation produced after seeing the answer. Reviewers can reasonably suggest removing the cache or correcting its key; they still need to demonstrate the failure.
Review quote.py against this contract: each call returns its current
unit_price_cents multiplied by its current non-negative quantity.
The same product may be quoted again with a changed price or quantity.
Inputs have already been validated.
Give one concrete call sequence that violates the contract, the expected
and actual result, and the smallest repair you would propose.
Do not change files or add dependencies. State any uncertainty.3. Run checks that keep history inside a single test
import unittest
from quote import QuoteBook
class QuoteTests(unittest.TestCase):
def setUp(self):
self.book = QuoteBook()
def test_first_quote(self):
self.assertEqual(self.book.total("pencil", 100, 5), 500)
def test_quantity_changes(self):
self.book.total("pencil", 100, 5)
self.assertEqual(self.book.total("pencil", 100, 3), 300)
def test_price_changes(self):
self.book.total("pencil", 100, 5)
self.assertEqual(self.book.total("pencil", 120, 5), 600)
def test_different_products(self):
self.book.total("pencil", 100, 5)
self.assertEqual(self.book.total("notebook", 250, 2), 500)
if __name__ == "__main__":
unittest.main()python3 -m unittest -v test_quote.pyThe deliberately faulty version should run four tests and fail two: test_quantity_changes receives 500 instead of 300, and test_price_changes receives 500 instead of 600. The first quote and different-product checks pass. A command that exits unsuccessfully at this stage is the expected observation. Keep the output as your before-repair evidence.
Each test receives a new QuoteBook, while the two calls inside a failure test share one instance. This arrangement makes the dependency clear and prevents test order from deciding the result. A test that creates a fresh object for every call would accidentally erase the condition that exposes the bug.
If you see an import error, check that both filenames are exact and your terminal is in the practice directory. If all four checks pass before the repair, inspect quote.py: you may already have the repaired version. If the expected two fail, compare the reported values before editing anything. A different failure needs an explanation before you proceed.
4. Remove the unnecessary retained state
class QuoteBook:
def total(self, sku, unit_price_cents, quantity):
return unit_price_cents * quantitypython3 -m unittest -v test_quote.pyThe repaired version performs one multiplication for each request. The product identifier remains in the method signature so callers keep the same interface. It is intentionally unused in this calculation. Removing the cache also removes the need to reason about invalidation, memory growth and key collisions in this exercise.
All four tests should now pass with an OK summary. Keep the tests unchanged between the failing and passing run. A repair that changes the expected price to match the stale value has changed the contract instead of fixing the function.
A cache keyed by every relevant argument could also satisfy this narrow contract. It would add state for a calculation that is already cheap. In a real system, measure the expensive operation before choosing that complexity. A passing exercise does not establish thread safety, input validation or checkout correctness outside the boundaries listed above.
5. Leave a review another person can verify
Subject: repeated quotes return a stale amount
Contract: current price in cents × current quantity
Reproduction: quote pencil at 100 × 5, then pencil at 100 × 3
Expected second result: 300
Observed before repair: 500
Cause: stored total is identified only by product, so changed inputs reuse it
Repair: calculate each request directly; keep the public method signature
Evidence: four tests, two expected failures before, all four pass after
Scope: validated integer inputs; no tax, discount, currency or persistence
Python version / date / reviewer:
Other untested assumptions:The finished deliverable is quote.py, test_quote.py, the two command outputs and this review note. A colleague should be able to reproduce the failure and the repair from that package. Do not report that an AI reviewer found the bug unless its saved first response actually did.
For a follow-up exercise, choose one item from WouldYouMerge and read its requirements first. Its README provides separate setup and checking commands for its own Python and JavaScript exercises. Use those instructions only after reviewing the project; the commands above apply solely to Current’s original example.
Repeat the review with a second fault category, such as a boundary value or a mutable object shared between requests. Keep each exercise small enough that the expected behavior can be explained in one paragraph. The useful habit is to connect a claim about correctness with a specific input, an observed result and a repeatable check.
Sources & next steps
GitHub · implementation
WouldYouMerge review exercises ↗
README describes deliberately buggy Python and JavaScript review exercises. Repository code was not downloaded or executed.
Sohail Khan · page checked 2026-10-17
Guide history
Revisions preserve the original instructions. A source recheck alone does not create a new revision.
Revision 1 · New original review exercise with complete failing and repaired code, four tests, expected output and a reusable review handoff.
Continue learning
Context Mode: shrink tool output without losing the clue
Install the documented Claude Code plugin, then test retrieval against an original incident log with two failures and a misleading success message.
Review an agent’s optimization before trusting the speedup
A complete Python exercise for checking values, shared state and timing before accepting a generated optimization.