What not to do, and how to do it
summary
Explains concrete behaviors: locals() vs globals() — locals returns a snapshot that doesn’t update fast locals while globals returns the module dict; uses inspect.currentframe and code objects to read the call stack, compare code objects and local names to allow attribute writes only from __init__ (it works but fails with closures and some inheritance patterns); disassembles and rewrites co_code to implement bytecode patching for goto and switch, a ~200‑line implementation that runs but is fragile across Python bytecode changes.
AI-written summary · about
chapters (7)
- 0:00Intro
- 1:25Local variables
- 4:40Cole stack
- 8:53immutable objects
- 13:35goto statements
- 14:25disassemble
- 19:25QA
related talks
28mThe chaotic locals() and how we fixed it
31mDon't Do This
28mFunction dissection lab -- learn how functions
50mExploring CPython's bytecode
30mHow to change Python (while it's running)
28mWhat makes a Python debugger possible and how can we make it 100x faster
43m5 Years of Bad Ideas
32mWriting performant code for modern Python interpreters
