Code as Data_ A Practical Introduction to Python’s Abstract Syntax Tree
summary
Shows a concrete claim: Python’s ast lets code be rewritten so pytest prints intermediate values instead of a bare AssertionError, by rewrites assert into intermediate variables that get printed in a try or boolean wrapper. Demonstrates tools that use this — pytest, linters, black, pandas query tweaks, dask and template engines like Ginga 2 — and practical limits: ast drops formatting and comments and AST shapes change across Python versions, yet the transformer example actually works and pytest uses @-named temps in its transformed trees.
AI-written summary · about
chapters (9)
- 0:00Introduction to abstract syntax trees
- 3:35Python execution flow
- 7:56Pytest AST errors
- 12:44Poor man's pytest
- 18:51Pytest assertions AST
- 21:00AST in tools
- 22:45AST refactoring
- 26:38Why AST matters
- 27:01Q&A
related talks
24mThe AST and Me
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
34mFinding and creating gambiarras with python ASTs
27mOh You Who Enter, Abandon All Hope
30mDoing stupid things with ASTs
25mPython as a Hackable Language for Interactive Data Science
28mSafely eval Python syntax using the AST module
22mDecoding: programming beyond text files
