Python, Read From the Source — a reading guide
A phased path through CPython and the standard library: the interpreter's own data structures, three stdlib files read line by line, the evaluation-model gotchas, and the craft of writing Python that reads the same way.
Phase 1 — The runtime, honestly
What the interpreter actually serializes when it runs your code, and how the one structure every object leans on actually works.
- The GIL, Honestly — One mutex around the interpreter, and yet x += 1 still races — watch the GIL op by op before you trust a threading answer.
- Python’s Dict, Under the Hood — Open addressing, the perturb probe, and the compact layout that made insertion order a language guarantee — the structure every object leans on.
Phase 2 — The stdlib, line by line
Three real files, walked start to finish: a condition-variable queue, the linked list under lru_cache, and the dunder protocols the whole language sits on.
- CPython’s queue.py, Line by Line — The real bounded blocking queue — one mutex, three Conditions — walked top to bottom in the actual Lib/queue.py.
- functools.lru_cache, Line by Line — The canonical thread-safe LRU, in production code: the circular doubly linked list and the one RLock that makes it safe.
- Iterators, Generators & the Dunder Protocols — Desugar the for-loop into iter / next / StopIteration and watch a generator freeze mid-frame on yield.
Phase 3 — Where Python bites
The evaluation-model rule under the gotchas everyone eventually hits, and the general mechanics of a race once two threads actually share memory.
- Python Gotchas That Fail Interviews — Eight snippets that look obvious and aren’t — the single evaluation-model rule under mutable defaults and late binding.
- Threads, Locks & the Anatomy of a Race — Share memory between two threads and the interleavings explode — the general mechanics under the GIL story, one lost update at a time.
Phase 4 — Writing it well
From a function a reviewer trusts on sight, to an idiomatic style, to an API whose invariants are load-bearing, to an honest error surface.
- Writing Python Interviewers Trust — One problem, solved twice — the rushed version and the trustworthy one, as six signals you can name and practise.
- Idiomatic Python — The same program with a C accent, then the way Python actually wants it written — comprehensions, EAFP, dataclasses, and when not to reach for them.
- Designing a Clean Python API Under Pressure — Derive the interface from the call site, state the invariants, shape the exception surface.
- Errors, Edge Cases & Testing in the Room — What breaks the happy path, enumerated — the edge-case checklist and a five-minute self-test before you call code done.