Sub topic 7
Follow up on the parts you don't understand
This chapter assumes you can read basic Python, have used a chat or terminal assistant, and can run small snippets locally. It also assumes you have already sent a first explanation prompt, such as the @lru_cache prompt from the previous chapters, and have the answer in front of you.
Why the first answer is rarely enough
A first explanation covers the whole snippet at a general level. Your confusion is usually narrower. You may follow most of it and be stuck on one phrase, one line, or one claim that doesn't match what you expected. Follow-up questions let you aim the assistant at that gap instead of asking for a longer explanation of everything.
Point at the exact spot
"I don't get it" forces the assistant to guess what you mean. Quote the part that confuses you and say what kind of confusion it is.
| Vague follow-up | Targeted follow-up |
|---|---|
| Can you explain more? | You said the cache is keyed on the arguments. What exactly is the key for `fib(5)`? |
| That's confusing. | In your walkthrough, `fib(3)` is computed once, but it is called from two places. Where does the second call get its value? |
| Is this safe? | What happens if I call `fib` with a list instead of an integer? |
Each targeted question has three parts: the claim or line you are asking about, what you already understand, and the specific thing you want resolved.
Useful kinds of follow-up
- Mechanism: "What does the decorator replace
fibwith?" This asks how the code works internally. - Counterfactual: "What would change if I removed
@lru_cache?" This shows what the line is for. - Boundary: "What happens with
n = -1, or withn = 5000?" This probes edge cases. - Evidence: "Which part of that depends on the Python version? Where in the documentation would I confirm it?" This separates certain claims from guesses.
- Restatement: "Here is my understanding in two sentences. What is wrong or missing?" This tests your own model directly.
Restatement is the most reliable of these. A wrong mental model is easy to spot when it is written down.
A worked example
Suppose the assistant explained fib and said the decorator "stores results so repeated calls are fast." You ask:
You said lru_cache stores results. Stores them under what key?
I'm wondering whether passing a list to fib would work. Tell me what you
are sure of, and show me a one-line way to test it.A good answer says the cache is keyed on the call's arguments, so every argument must be hashable. A list is not hashable, so the call should fail with a TypeError. You can confirm this yourself:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
print(fib(10))
try:
fib([5])
except TypeError as error:
print("TypeError:", error)The first line prints 55. The second prints TypeError: unhashable type: 'list'. The assistant's claim now rests on something you observed, not only on its wording.
Keep the thread, and keep it short
- Ask one question per message. Several questions in one message tend to get shallow answers, and you can't tell which answer addressed which question.
- Stay in the same conversation while you are still on the same code. The assistant can refer back to its earlier walkthrough. If the conversation has become long or tangled, start a new one and paste in only the code and your current question.
- Correct it when you know better. If your test contradicts a claim, say so and include the output. "I ran this and got X, but you said Y. Why?" usually leads to a useful correction.
- Watch for drift. If a follow-up answer contradicts the first one without acknowledging it, ask which one is right and why. Don't pick one by default.
Know when to stop asking
Stop and verify when the answers become repetitive, when you are asking about behavior you could just run, or when the explanation depends on facts the assistant can't see, such as your installed version or your project's configuration. Running code is faster and more reliable than a fifth round of questions. The next chapters cover where assistants go wrong and how to check an explanation independently.
Exercise
An assistant explains @lru_cache(maxsize=None) and says the cache "never forgets anything." You are unsure what that means for a long-running service that calls the function with many different inputs. Write one targeted follow-up question, and name one way to check the answer yourself.
Show answer
A good follow-up: "You said the cache never forgets. With maxsize=None, does memory use grow with each new distinct argument? How would I observe that, and what would I change to bound it?" To check it yourself, call the function with many distinct inputs and read fib.cache_info(). The currsize value should grow with each new input. Then change maxsize to a number such as 128 and confirm that currsize stops at that limit.