Syllabus Lesson 99 of 148 · Judge the output
Judge the output

Changes nobody asked for

Why it matters You asked for a one-line fix. The diff also changes how totals are rounded. Reviewers read the part they asked about; the rest ships.

The assistant output in this lesson was written for the course in the exact shape real assistants produce. It is not a recording of any particular model.

A unified diff (what git diff prints) has a header per file and then hunks. Each hunk starts with a line like @@ -40,7 +40,7 @@ def apply_discount(order, code):; the text after the second @@ is the function or class the change sits in. Inside a hunk, lines start with a space (unchanged), - (removed) or + (added).

The text after the second @@ is only git's hint: the nearest line above the hunk that looks like the start of a function or class. For Python files without *.py diff=python in .gitattributes, a method change often shows its class line, and a hunk that starts above a new def names the function before it. This tool trusts the hint, which is good enough to make a reviewer look; set the attribute (or parse the file) when you need it exact.

The worked example

You asked for a fix to apply_discount. The assistant's diff:

diff --git a/app/orders.py b/app/orders.py
index 3f2a1c0..9b7e4d2 100644
--- a/app/orders.py
+++ b/app/orders.py
@@ -40,7 +40,7 @@ def apply_discount(order, code):
-    if code.percent > 100:
+    if code.percent >= 100:
@@ -88,6 +88,6 @@ def total(order):
-    return round(sum(l.price for l in order.lines), 2)
+    return sum(l.price for l in order.lines)
@@ -120,4 +120,4 @@ class Order:
-    status = "new"
+    status = "open"
diff --git a/db/reports.sql b/db/reports.sql
index 77ab12c..e09f3d1 100644
--- a/db/reports.sql
+++ b/db/reports.sql
@@ -1,3 +1,3 @@
 SELECT id, total
--- totals are rounded in total()
+-- totals are no longer rounded
 FROM orders
diff --git a/app/flags.py b/app/flags.py
new file mode 100644
index 0000000..1c2d3e4
--- /dev/null
+++ b/app/flags.py
@@ -0,0 +1,2 @@
+FAST_CHECKOUT = True
+

Beyond what you asked, it changed total (rounding is gone), a default inside class Order, a comment in a SQL file (no function there, so <module>), and added a whole new file. Note the line --- totals are rounded in total(): it is a removed SQL comment (- plus -- totals...), not a file header.

Your turn

Write unrequested(diff, asked). asked is a set of function or class names the request was about. Return a sorted list of (path, name) pairs, each once. Files: a file starts at diff --git; before its first hunk, --- a/PATH and +++ b/PATH give its path (drop the a/ or b/). If the --- side is /dev/null, report (path, "<new file>"); if the +++ side is /dev/null, report (path, "<deleted>") (path from the --- side); nothing else is reported for those files. Hunks: for every other file, each hunk belongs to the name after the second @@: the name in def NAME(, async def NAME( or class NAME, or "<module>" if there is no such text. Report (path, name) when the name is not in asked. Inside a hunk, a line starting with --- or +++ is content, not a header.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.