🐍 Python for Everyone

← Back to the project

Chapter 29 — Solo → AI-Paired → Critique 25 min

Now Pair With an AI

Step 1: You already built this solo

You just built the Open-Source-Style Collaboration Workflow yourself, unaided — forking, branching, pushing, and syncing with real git commands. That project is unchanged — this page is additive. This time, instead of asking an AI to write code, you'll ask it to help with two things that come up constantly in real collaboration: writing a PR description, and deciding how to respond to review feedback. Read its advice with the same skepticism you'd bring to a coworker's Slack message before actually following it.

Step 2: Now pair with an AI

Picture this: you extended recipes.py from the main project further. The catalog used to store each recipe as a plain list of ingredient strings (RECIPES["pancakes"] == ["flour", "egg", "milk"]). You changed it to a dict mapping each ingredient to a quantity (RECIPES["pancakes"] == {"flour": "2 cups", "egg": "1", "milk": "1 cup"}), so `servings_for()` can print real quantities instead of just listing ingredient names. You've pushed the branch and you're about to open the PR. Here's the prompt you give an AI assistant:

the-prompt.txt
Write a pull request description for this change: I changed the
RECIPES dict in recipes.py so each recipe's value is now a dict of
{ingredient: quantity} instead of a plain list of ingredient name
strings, so servings_for() can print real quantities. Keep it
concise but cover what a reviewer needs to know.

And here's a plausible response — the kind of description an AI assistant might hand back on the first try. Read it as if it just landed as a real PR on GitHub, before scrolling to the critique below.

pr-description.md
## Add ingredient quantities to the recipe catalog

**What changed**
`servings_for()` now returns actual ingredient quantities (e.g.
"2 cups flour") instead of just listing ingredient names. This makes
the output genuinely useful for someone who wants to actually cook
the recipe, not just see what's in it.

**Why**
The old output ("pancakes for 4 people uses: flour, egg, milk") told
you *what* you needed but not *how much* — not very actionable for
an actual kitchen.

**How to test it**
Run `servings_for("pancakes", 4)` and confirm the output now includes
quantities for each ingredient.

**Notes for the reviewer**
Nothing else changed — this is a self-contained improvement to the
formatting logic.

It reads well, it's got all four sections the chapter's own PR-description template calls for, and the tone is exactly right for a real PR. It's also missing something that would matter a lot to any teammate reading it — and, separately, you also asked the same assistant a follow-up question about review feedback that came back with equally confident, equally incomplete advice.

Step 2b: the follow-up question

A reviewer leaves an inline comment on your PR: "Can you rename servings_for to ingredients_with_quantities_for — the current name doesn't reflect what it returns anymore." You make the rename locally, but your branch has drifted a bit from what's on GitHub (you rebased onto the latest main to pick up an unrelated fix), so a plain push is rejected. You ask the assistant what to do:

the-followup-prompt.txt
I rebased my PR branch onto the latest main and made the rename my
reviewer asked for, but `git push` is rejected because the remote
branch has diverged. How do I get my changes up?
ai-response.txt
That happens whenever you rebase a branch that's already been pushed
— the rebase rewrites your commits' hashes, so the remote no longer
recognizes your local history as a continuation of what it has.
Just force it through:

    git push --force origin add-recipe-quantities

That'll overwrite the remote branch with your rebased version and
your rename will show up in the PR right away.

The command itself will, in fact, get the rename onto GitHub. That's exactly what makes this worth pausing on.

Step 3: Where did the AI's advice lie to you?

Click to see the critique

What it looks like it does: the description covers what changed, why, how to test it, and has a "notes for the reviewer" section explicitly stating "nothing else changed — this is a self-contained improvement" — it looks thorough and honest about scope.

What it actually does: RECIPES["pancakes"] changed shape entirely — from a list of strings to a dict of ingredient-to-quantity pairs. Any other code (in this repo or, worse, in a downstream fork or a different branch someone else is working from) that does for ingredient in RECIPES[name] expecting plain strings, or that indexes it like a list, breaks silently or outright crashes the moment it touches the new shape. The description's "notes for the reviewer" section actively claims the opposite of the truth — "nothing else changed" is precisely wrong for a change that alters a shared data structure's type.

Why it matters: a breaking change to a shared data structure is exactly the kind of thing a PR description exists to surface loudly, not bury. A reviewer who trusts the "notes for the reviewer" section at face value has no reason to go check whether anything else in the codebase reads RECIPES the old way — and finds out the hard way, after merge, when something else breaks.

The fix: the description needs an explicit "Breaking change" callout: RECIPES[name] used to be a list of ingredient strings and is now a dict of {ingredient: quantity} — any other code reading this structure directly needs to be checked and updated. This is exactly the kind of "anything risky or non-obvious" content this chapter's own PR-description template calls for, and it's the one thing this AI draft quietly dropped.

What it looks like it does: the response correctly diagnoses why the push was rejected (a rebase rewrites commit hashes, so the remote branch and the local branch no longer share a common history the way a normal fast-forward push expects) and gives a command that will, in fact, resolve the immediate error.

What it actually does: git push --force unconditionally overwrites whatever is on the remote branch right now with your local version — with zero check for whether anything changed there since you last fetched. Two concrete risks it never mentions: first, the reviewer's inline comment that's still open on this PR is anchored to a specific commit on the branch; once that commit no longer exists after a force-push, GitHub can lose the live anchor for that comment's context (this chapter's own interview questions cover exactly this). Second, if a teammate had pushed anything to this same branch in the meantime — a small fix, a suggested change applied directly — a plain force-push discards it permanently with no warning, no diff shown, nothing to undo.

Why it matters: the advice isn't wrong about what unblocks the push — it's wrong by omission. A response that hands over a command with real, irreversible failure modes, with no mention that a materially safer version of the same command exists, is teaching "force it through" as the default instinct on a shared branch — exactly backwards from how experienced teams actually operate.

The fix: use git push --force-with-lease origin add-recipe-quantities instead. It performs the identical rewrite when nothing unexpected has happened on the remote, but refuses the push and tells you plainly if the remote has commits your local copy hasn't seen — turning a silent, unrecoverable overwrite into a stop-and-check moment. On a solo branch nobody else touches, plain --force is low-risk; on any branch open for review, --force-with-lease should be the default reflex, not an afterthought.

Step 4: Your entry for this chapter's playbook

Fill this in for yourself — it's not saved or sent anywhere, just yours to keep (copy it into your own notes before you close this tab).

← Back to the Project All Chapters →