Fix a bug, and prove it stays fixed
A cleanup routine is supposed to remove every expired item from a list, and users report that some expired items survive. The code removes items from the list while iterating over it. Find the cause, write a test that fails because of it, then fix it. Hand in the test, the fix, and a short note. The note matters as much as the code: say what the failure was in terms of what Python actually does, not in terms of what the user saw.
What you have to hand in
- A test that targets the reported failure, with a name that says what it covers.
- A statement of what the test did before the fix, quoting the output.
- The fix, confined to the cause.
- Two or three sentences naming why the original loop skipped items.
The checklist, published before you start
- The cause is named, not just the symptom
The submission says what was actually wrong, at the level of the line and the language rule involved — not merely what the user saw.
- Restates the symptom, or describes the change without saying why it was needed.
- Names the region of the problem but not the rule that made it fail.
- Names the line and the behaviour that caused it.
- Names the cause and rules out a plausible competing explanation.
- A test that would have caught it
There is a test targeting the reported failure, and the write-up states what it did before the fix.
- No test, or a test that cannot fail regardless of the fix.
- A test exists but exercises a different case than the one reported.
- A test covers the reported case, and the author says it failed before the fix.
- Covers the reported case and a neighbouring edge case, with the failure output quoted.
- The fix is the smallest one that works
The change addresses the cause and does not rewrite surrounding code that was not implicated.
- Rewrites unrelated code, or changes behaviour the brief did not ask about.
- Fixes it, but carries incidental refactoring along with it.
- A targeted change confined to the cause.
- Targeted, with the larger rewrite explicitly considered and declined.
- A colleague could follow it
Names say what things are; the diff can be read without the author present.
- Single-letter names, or a change that cannot be understood without asking.
- Understandable after a second read.
- Clear names and an obvious shape.
- Reads as an explanation of the bug as well as a fix for it.
The skills a pass would prove
- Loops and iterationIterate over a collection idiomatically, including in parallel with another
- Reading a tracebackLocate the cause of a failure from its traceback and say which line is at fault
- Writing testsWrite a test that fails for the right reason before the code is fixed
- Lists and tuplesChoose between a list and a tuple and justify it from how the data is used
This brief is part of the Python Fundamentals course
Starting it starts the course: every skill above, in the order they depend on each other, with this brief at the end as the thing you hand in — marked against the checklist you have just read and nothing else.
Start the Python Fundamentals course