Digging into Abstract Syntax Trees for analyzing and modifying Python programs
summary
Shows how to parse source with inspect.getsource and ast.parse, walk trees with ast.NodeVisitor to collect defined vs called names using set difference, and transform code with ast.NodeTransformer to inject print nodes and recompile to bytecode. Builds python-morg to find dead code and deletes roughly 150–200 unused functions, mentions macro_py for safer macro-like rewrites and mutation testing for fuzzing unit-test coverage.
AI-written summary · about
chapters (8)
- 0:00Start
- 0:40Can You Write a Python Program That Takes a Python Program as Input
- 0:59Abstract Syntax Trees
- 2:39Abstract Syntax Trees
- 3:50Node Visitor and Node Transformer
- 5:11Node Visitor
- 6:52Convenience Method Dump
- 24:17Mutation Testing
related talks
28mPractical Python parsing with the ast standard module
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
27mOh You Who Enter, Abandon All Hope
27mAST Meta-programming
33mSource code processing with Python
01h 02mTransforming an Abstract Syntax Tree into Groovy. WHAT?!
45mClimbing the Abstract Syntax Tree
29mMy Little Parser: Tooling is Magic
