Read Code Fast
Lesson 15 A file in 60 seconds
exports, types, entry point, happy path, then stop
What you'll learn
- Read a file from the outside in: exports, imports, signatures, happy path
- Say which lines are the file's front door and which are risky
- Stop early and know where to look next
A new file can be 300 lines long. You don't need 300 lines to know what it is for. You need about 60 seconds and a few questions, asked in order.
The idea
Read a file from the outside in. 1. What it offers: the public names are its front door (in Python every top-level name is public, but one or two matter). 2. What it leans on: the imports tell you if it touches the database, the disk or email, and those are the risky lines. 3. The signatures: the names, inputs and type hints. 4. The happy path: follow one normal request from top to bottom. 5. Stop.
Error branches, helpers and edge cases are read only when a question needs them. The goal is not to understand the whole file. It is to know where to look when you need to.
1from fastapi import APIRouter2from app.db import orders3from app.mail import send_receipt4from app.schemas import OrderIn56router = APIRouter(prefix="/orders")7TAX_RATE = 0.289def total_with_tax(items): ...1011@router.get("/{order_id}")12def read_order(order_id: int): ...1314@router.post("", status_code=201)15def create_order(body: OrderIn):16 order = orders.insert(body)17 send_receipt(order)18 return order
- Line 2 Imports tell you what the file leans on: a database and email. Those are the risky calls.
- Line 6 The front door. Python has no
exportline, so look for the name the app uses: hererouter. - Line 9 A helper. The name and the input are enough for now. Don't read the body yet.
- Line 16 The happy path of POST: save the order, send the receipt, return it. The order is saved before the receipt is sent: keep that as a question.
Take away
- Read a file from the outside in: what it offers, what it leans on, the signatures, one happy path.
- Then stop. Read the rest only when a question sends you there.
- Reading order is not running order: check what runs when the file loads.
Quiz: test yourself
7 questions: a quick quiz, then a review drill. Pick an answer to see why it's right.