The AST and Me
summary
Python source parses to an AST that the compiler transforms into a control‑flow graph and immutable code objects (look at co_consts and co_code), then emits bytecode stored in .pyc files. Use the built‑ins ast module to inspect/modify trees and dis module to read opcodes. Expect small compiler tweaks like peephole optimization and constant folding; larger speedups require alternate implementations. Real results: code generators, linters and formatters (Hypothesis, Jinja, black), and transpilers that actually run.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 2:06Python compiled or interpreted
- 2:44Process overview
- 3:45What is an AST
- 4:04What is a tree
- 6:46AST Parse
- 8:44Code Objects
- 15:37Constant Folding
- 16:29How the AST affects your code
- 17:52Examples of AST projects
- 21:36Conclusion
related talks
27mPython: From Source to Execution
32mCode as Data_ A Practical Introduction to Python’s Abstract Syntax Tree
36mHacking the Python AST
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
30mDoing stupid things with ASTs
27mCPython's Compilation Pipeline
54mClimbing the Abstract Syntax Tree
27mOh You Who Enter, Abandon All Hope
