Hacking the Python AST
summary
Clones CPython from GitHub and edits its grammar and AST pipeline to prove changes take effect at runtime, using the stdlib ast module with ast.NodeVisitor and ast.NodeTransformer to traverse and rewrite code. Builds a flake8 plugin that emits a custom X9000 error for single-letter function names. Demonstrations include renaming variables across code, mapping names to dictionary lookups, and a live parser modification that makes localized keywords behave differently — all shown working on an actual Python build.
AI-written summary · about
chapters (9)
- 0:00Introduction and setup
- 3:53Philosophy of hacking
- 10:36Compiler architecture
- 14:34Python internals
- 16:22Grammar and LL(1)
- 20:34Bytecode experimentation
- 23:07AST manipulation
- 28:08Building custom tools
- 33:56Q&A and conclusion
related talks
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
24mThe AST and Me
30mDoing stupid things with ASTs
31mSupercharge your Python library using AST parsing
27mOh You Who Enter, Abandon All Hope
34mCompiling Pythons with Custom Grammar for the sake of a joke
34mFinding and creating gambiarras with python ASTs
25mPython as a Hackable Language for Interactive Data Science
